Skip to content

Fix: Use user-configured pinned_id instead of array index#78

Merged
eyalgal merged 3 commits intoeyalgal:mainfrom
andrewfoster:main
Jan 26, 2026
Merged

Fix: Use user-configured pinned_id instead of array index#78
eyalgal merged 3 commits intoeyalgal:mainfrom
andrewfoster:main

Conversation

@andrewfoster
Copy link
Copy Markdown
Contributor

Summary

The _getPinnedTimers() function was setting pinned_id to the array index (pinned-${idx}) instead of using the user-configured id field from the pinned timer configuration.

Problem

When users configure pinned timers with an id field (e.g., id: study_1h), that ID was not preserved in the pinned_id field. Instead, the code was using the array index (e.g., pinned-0), making it impossible to reliably identify which timer triggered an event via MQTT.

Solution

Modified the _getPinnedTimers() function to use the user-configured id field when available, falling back to the array index only if no id is provided.

Before

pinned_id: `pinned-${idx}`,

After

pinned_id: (p && typeof p === "object" && p.id) ? p.id : `pinned-${idx}`,

Impact

This fix ensures that:

  • User-configured timer IDs are preserved in MQTT events
  • Automations can reliably identify which timer triggered an event
  • The pinned_id field in MQTT payloads now contains the expected user-configured value

Example

Dashboard Configuration

pinned_timers:
  - id: study_1h
    name: Study 1 Hour
    duration: 1h

MQTT Event (After Fix)

{
  "id": "custom-1737636400000",
  "pinned_id": "study_1h", // Now correctly uses user-configured ID
  "label": "Study 1 Hour",
  "event": "expired"
}

Automation

action:
  - action: climate.turn_off
    target:
      entity_id: >
        {% set pinned_id = trigger.payload_json.pinned_id %}
        {% set entity_name = pinned_id | regex_replace('_.+$', '') %}
        {{ 'climate.' ~ entity_name }}

Related Issues

This fix enables use of pinned_id prefix-based identification for HVAC timer automations, as described in related documentation.

The _getPinnedTimers() function was setting pinned_id to array
index (pinned-${idx}) instead of using the user-configured id field
from the pinned timer configuration.

This fix ensures that when users configure pinned timers with an id field
(e.g., id: study_1h), that id is preserved in the pinned_id field
and included in MQTT events, allowing automations to reliably identify
which timer triggered the event.

Before: pinned_id: pinned-0
After: pinned_id: study_1h
@eyalgal eyalgal merged commit 65978f2 into eyalgal:main Jan 26, 2026
1 check passed
@eyalgal
Copy link
Copy Markdown
Owner

eyalgal commented Jan 26, 2026

Thanks for the contribution! This is now live in v2.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants