it wonât work because youâre âmarryingâ state and template triggers
read the docs more carefully
the approach really depends on what you want to achieve.
if your sensor.tumble_dryer_power returns a number (itâs a string but if itâs a valid number like â12â) you can use state trigger + template condition
- alias: bbb
trigger:
platform: state
entity_id: sensor.tumble_dryer_power
condition:
condition: template
value_template: >
{{
trigger.to_state and
trigger.to_state.state and
trigger.to_state.state not in ['unknown', 'unavailable'] and
and trigger.to_state.state|int > 10
}}
action:
but it will perform action when sensor.tumble_dryer_power is 11, 12, 13 etc.
If you need it to run only once, use numeric state trigger
ahh ok, I should have set the value as a condition, seems pretty obvious now
however my sensor returns â1500 Wâ (as an example) so isnt a numeric value due to W at the end which im trying to remove with my original value_template
sensor.tumble_dryer_power doesnât exist. You would have wanted states.sensor.tumble_dryer_power
But even if you had it right, this would be a state object, not a string.
states.tumble_dryer_power.state is the actual state. Or, states(âsensor.tumble_dryer_powerâ) would be better in the event that sensor doesnât exist (would return âunavailableâ).
trigger:
platform: template
# If the conversion to float fails, this will return 0.0 and will be false.
value_template: "{{ states('sensor.tumble_dryer_power').replace(' W','')|float > 10.0 }}"
ok this makes no sense to me, Ive been back over the documentation and it appears what I am trying to do is correct.
it makes no sense to constantly trigger on the state of the device and then add a condition, when the UI itself gives me the option to trigger above and below a numeric value
really all im trying to do is remove the â Wâ from the end of the string to use a numeric function on it, is it really this difficult or am I missing something obvious?
It lops off the last two characters of whatever value is returned by states('sensor.tumble_dryer_power'), converts it to an integer, then checks if itâs greater than 10.
and it will trigger only once when the value exceeds 10 and wonât trigger until it falls to 10 or below and then again exceeds 10.
adding this note as the TS did not tell if heâs happy with such a scenario.
Cheers guys, yeah im happy with the solution to just trigger above 10 as I will just make another automation for less then 10 or null as I want different actions to happen dependant
Sorry, what have I missed here ? Why not use the numeric state trigger ?
From the docs : -
automation:
trigger:
platform: numeric_state
entity_id: sensor.temperature
# Optional
value_template: "{{ state.attributes.battery }}"
# At least one of the following required
above: 17
You can even dispense with the template (and no need far a condition at all) cleaner, simpler, less processor intensive
In the original template, it removes a trailing " W" from the stateâs value. That implies itâs not just a pure number. I donât think the Numeric State Trigger works with a value like "12.5 W".