snarky-snark / home-assistant-variables

A custom Home Assistant component for declaring and setting generic variable entities dynamically.
Apache License 2.0
274 stars 16 forks source link

`tracked_entity_id` stops updating the variable when hot-reloading the configuaration #73

Closed zanna-37 closed 2 years ago

zanna-37 commented 2 years ago

When using tracked_entity_id, the variable stops updating if I hot-reload the integration (dev tools > YAML configuration reloading > variable). The issue is fixed after a reboot.

var:
  test_var:
    restore: true
    value_template: >
      {% set entity='sensor.test' %}
      {% set self_ref='var.test_var' %}
      {% if states(entity) not in ['unavailable', 'unknown', 'none'] %}
        {{ states(entity) }}
      {% else %}
        {{ states(self_ref) }}
      {% endif %}
    tracked_entity_id:
      - sensor.test
snarky-snark commented 2 years ago

Thanks for the report!

The issue appears to be that variable event listeners are only being set on HA startup.

https://github.com/snarky-snark/home-assistant-variables/blob/99f8015ea8c275465254cd9b7d4f65f6d7020be1/custom_components/var/__init__.py#L301

snarky-snark commented 2 years ago

I think this is fixed now. Is it possible for you to update to the develop version of this component to see if it fixes your issue? Thanks!

zanna-37 commented 2 years ago

Yes, thank you very much! Everything seems working now. Great job!