enkama / hass-variables

Home Assistant variables component
90 stars 12 forks source link

Changes to value of variables not picked up by alert integration #67

Closed cerebrate closed 1 year ago

cerebrate commented 1 year ago

There seems to be an issue with changes to the value of variables not being picked up by the alert integration (and possibly other integrations that use the same mechanism).

In context, I'm using a binary_sensor variable to transform a momentary event into a state that persists until manually cancelled. Having defined the variable, I set it when the event occurs and reset it when the user cancels with the variable.update_binary_sensor service. This works correctly: inspecting the value of the variable with the developer tools shows its value changing appropriately.

However, I then define an alert based on the value of the variable:

  alert:
    # An appliance beeped recently.
    appliance_beeped_recently:
      name: Appliance Beeped Recently
      entity_id: binary_sensor.appliance_beeps_recently
      state: 'on'
      repeat: 10
      skip_first: false
      message: "An appliance is beeping in the kitchen."
      notifiers:
        - loud

And this doesn't work. When the variable binary_sensor.appliance_beeps_recently changes state to on, the alert stays in idle, untriggered.

As a temporary workaround, if I define a simple binary sensor template which just passes through the state of the variable:

  template:
    - binary_sensor:
        - name: appliance_beeps_workaround
          state: "{{ states('binary_sensor.appliance_beeps_recently') }}"

the state of the template changes in sync with the state of the variable, as it should, and if I then use the binary sensor created by the template in the alert, the alert works correctly then, even though it doesn't work when configured to use the variable directly. So it looks like there's something funky in how this integration and alert play together...

Snuffy2 commented 1 year ago

I tried a binary_sensor Variable with a test Automation and it works fine. Does it work for an Automation for you? I'll try an Alert next.

2023-06-26_19-54-12 519 2023-06-26_19-53-51 352 2023-06-26_19-55-14 526 2023-06-26_19-54-51 902
Snuffy2 commented 1 year ago

It's working for Alerts too. Not sure what may be different.

2023-06-26_20-10-37 902 2023-06-26_20-12-15 239 2023-06-26_20-11-54 226
cerebrate commented 1 year ago

Sorry for the delay in getting back to you. We had something of a disaster last week that interfered with that, and also took out most of our computer equipment in the process, and we're only just getting back on our feet. Once I get Home Assistant back up, I'll reopen this if the problem recurs.

In the meantime, thanks for looking into it.