Can someone help me with this, I’m trying to trigger some events using the attibutes of weather sensors, for temperature.
But i dont know where to start, all tiggers are for entities and not attributes
I just want to turn on a fan when the temperature is higher than 24C.
Home Assistant is an entity state model, and all state changes are announced on the ‘event bus’. The HA WebSocket nodes register with the bus, and the
Events: all
Events: state
Trigger: state
nodes will listen out for all events / all state change events
This applies to all entities, and each entity has a state value, so any change to the state value will trigger an event (state change) on the event bus. However, entities can have attributes, and any change to an attribute also triggers a state-change event - even if the state value has not changed.
Therefore, if you use for example the Events: state node, and set it to listen for state changes on your weather entity (sensor), then when either the state or any of the attributes change value, the node will pick this up.
The trick is to untick - Ignore state change event when - Current state equals previous state
If just an entity attribute value changes (and not the state value) then the current state will equal the previous state, and in this case you want this to trigger a flow.
If you want to set the reverse test up - that is to only fire when an attribute has changed and not the state value, then you need a bit of JSONata in the conditional test.
Using JSONata for the test option, and
$entity().state = $prevEntity().state
and leaving the Ignore state change event when current state equals previous state unticked, the node will fire and exit from the top only when an attribute has changed and the state value has not changed.
This now opens the opportunity to perform your ‘temperature higher than 24’ test directly. Using
$entity().attributes.temperature > 24
does the job.
Another option would be to use the trigger state node.
In the property field, the new_state
prefix refers to the entity’s current state, while the old_state
prefix represents its previous state.
You trigger on the entity state change and then check the attribute state in the following node.
this worked perfectly, thanks