@state_trigger does not trigger on climate domain, attribute changes
In general, there appears to be a hit or miss state trigger situation with the climate domain. For instance, the following
@state_trigger('climate.my_thermostat.hvac_action')
does not trigger on hvac_action but only on hvac_mode changes.
to workaround that, I tried adding a watch:
@state_trigger('climate.my_thermostat.hvac_action', watch=['climate.my_thermostat.hvac_action'])
which made it trigger on the hvac_action attribute but the value/old_value I get, are both from the hvac_mode.
meaning, inside the trigger I have to explicitly get the value of the climate attribute hvac_action.
Another problem that I could not work around easily this time, was trigger on the climate current_temperature attribute.
Even with a watch, I can't get it to trigger. It only triggers for hvac_action changes.
Example:
@state_trigger('climate.my_thermostat.current_temperature', watch=['climate.my_thermostat.current_temperature'])
This one, just does not want to trigger on current temperature changes. It triggers on hvac_mode changes, instead.
Same thing, even with the *, like so:
@state_trigger('climate.my_thermostat.*', watch=['climate.my_thermostat.*'])
It will only trigger again, on hvac_mode changes and NOT on current_temperature changes.
My more involved workaround, was making a service with pyscript, that gets called by a HA "native" trigger on the current_temperature attribute changes, so that I can capture changes to that attribute. But that now has created a tightly coupled service/function to a HA trigger, which is not ideal. My pyscripts should be standalone.
Thank you.
-
By default when only the entity is specified, such as
@state_trigger('climate.my_thermostat.hvac_action'), it triggers only when the actualstatevalue changes. You can find what an entity uses asstatevalue in Developer Tools > States. In the case of a climate entity,stateishvac_modeso thereforehvac_actionis treated as an attribute only and would not trigger the bare decorator. This is likely working as intended. -
Now, when drilling down to the entity attribute
@state_trigger('climate.my_thermostat.hvac_action'), I too am only getting the kwargs for the entitystatevalue (in this casehvac_mode) passed to the function and not anything dealing with the intended attribute, requiring a explicit call tostate.get()within the function. This seems to be the same regardless of entity type or ifwatchis specified in the decorator. It would be nice to know if this is intended behavior or not, and in general I personally would like a bit more clarity on thewatchparamater, maybe an example or use case because I read the documentation multiple times and still don't fully understand it.
For example, on a color tunable lightbulb:
@state_trigger("light.shelf_strip.brightness")`
def test_brightness_change(**kwargs):
log.warning(f"brightness change: {kwargs}")
logs
brightness change: {'trigger_type': 'state', 'var_name': 'light.shelf_strip', 'value': 'on', 'old_value': 'on', 'context': <homeassistant.core.Context object at 0x7f44ee884f50>}
and nothing regarding the brightness attribute, with or without a watch=
- I could not replicate your
current_temperatureissue, the decorator triggers on the attribute change just fine for me as long as it's specified in the decorator.