Thank you!
I’m going to give this one a try.
If you want to ‘test’ it, you can go into the developer tools under /states/ : /change states/ and update the values of the two sensors to trigger the automation manually for testing purposes.
Thank you, I tested it and it worked!
I did not know you couldn’t use templates in conditions.
I’m shocked to see this, a few years ago a lot of fields that was just values was made to values or templates. Strange that this was not fixed.
But yes the way Rob posted was what I was thinking.
Thank you, I appreciate your help a lot.
I have a working automation now and learned new things.
For future reference:
I used the suggested code with the triggers as a value template.
Unfortunately the automation also triggers when just one condition is met.
Both conditions/triggers need to be met before it should activate.
Is there a way to alter the code to accomplish this?
Can I copy/paste the code from the triggers in conditions?
alias: Luchtverversing AAN (Temp/Hum) (Template)
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.werk_temp') | float(0) > states('sensor.cp_temp') |
float(0)
and states('sensor.werk_humi') | float(0) > states('sensor.cp_humi') | float(0) }}
condition: []
action:
- type: turn_on
device_id: 102103dc3ec38e21c9c878478ca2bde0
entity_id: switch.droger_stopcontact
domain: switch
- type: turn_on
device_id: 58913d5702500b426a217c63eb1b979d
entity_id: switch.lucht_toevoer
domain: switch
- device_id: 665e1de5daaaedefd9e0e553a5b0249e
domain: mobile_app
type: notify
message: Luchtverversing AAN (Temp/Hum) (Template)
mode: restart
If you mean this (shown below) then the two Numeric State Conditions are implicitly ANDed. It means both must evaluate to true
in order for the automation to execute the actions. If one of the two evaluates to false
then it terminates (no actions are executed).
condition:
- condition: numeric_state
entity_id: sensor.werk_humi
above: "{{ states('sensor.cp_humi') | float(0) }}"
- condition: numeric_state
entity_id: sensor.werk_temp
above: "{{ states('sensor.cp_temp') | float(0) }}"
If you doubt it, examine the automation’s trace and it will show both conditions reported true
(for the actions to be executed).
But isn’t these conditions the same as the template trigger he posted?
There shouldn’t be a need for conditions
If I understood RickyM’s comment correctly, he claimed:
Unfortunately the automation also triggers when just one condition is met.
If condition
contains two State Conditions (as shown above) then both must be true
, not just one, for action
to be executed.
If RickyM was referring to some other conditions then I misunderstood the comment.
I believe it was wrongly worded.
The “conditions” was the two states in the template trigger.
I see. I thought RickyM’s comment was about the two State Conditions in the original example (i.e. the example you had suggested). Because, after claiming it triggers when only one State Condition is met, he posts a new example that incorporates the State Conditions from the original example directly in a Template Trigger.
I’m sorry if I caused confusion. I’m also confused now
The below code has two triggers as a value template, no conditions.
If one of the two triggers is true the automation will activate.
alias: Luchtverversing AAN (Temp/Hum) (Template)
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.werk_temp') | float(0) > states('sensor.cp_temp') |
float(0)
and states('sensor.werk_humi') | float(0) > states('sensor.cp_humi') | float(0) }}
condition: []
action:
- type: turn_on
device_id: 102103dc3ec38e21c9c878478ca2bde0
entity_id: switch.droger_stopcontact
domain: switch
- type: turn_on
device_id: 58913d5702500b426a217c63eb1b979d
entity_id: switch.lucht_toevoer
domain: switch
- device_id: 665e1de5daaaedefd9e0e553a5b0249e
domain: mobile_app
type: notify
message: Luchtverversing AAN (Temp/Hum) (Template)
mode: restart
The automation should only activate when both triggers are true.
How can I alter this code to accomplish this?
Can I just copy/paste the code from the trigger section in the condition section?
Like this:
alias: Luchtverversing AAN (Temp/Hum) (Template)
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.werk_temp') | float(0) > states('sensor.cp_temp') |
float(0)
and states('sensor.werk_humi') | float(0) > states('sensor.cp_humi') | float(0) }}
condition:
- platform: template
value_template: >-
{{ states('sensor.werk_temp') | float(0) > states('sensor.cp_temp') |
float(0)
and states('sensor.werk_humi') | float(0) > states('sensor.cp_humi') | float(0) }}
action:
- type: turn_on
device_id: 102103dc3ec38e21c9c878478ca2bde0
entity_id: switch.droger_stopcontact
domain: switch
- type: turn_on
device_id: 58913d5702500b426a217c63eb1b979d
entity_id: switch.lucht_toevoer
domain: switch
- device_id: 665e1de5daaaedefd9e0e553a5b0249e
domain: mobile_app
type: notify
message: Luchtverversing AAN (Temp/Hum) (Template)
mode: restart
It shouldn’t, it’s not two triggers, it’s one trigger with four entities in a template combined with an and.
Because there is an and
it should only trigger when both parts are true.
It would be interesting to see the trace when it triggered.
It could actually be that because the float filter defaults to 0, if there was a brief unknown value then it could trigger.
If cp_temp and cp_humi was unknown they got defaulted to 0 and that would probably make it trigger
That wouldn’t work.
If it passed the trigger then it would pass the condition also.
This is what I find in the trace.
I can’t see any mention of sensor.cp_temp, sensor.werk_humi and sensor.cp_humi
Triggered by the sensor.werk_temp via template at August 31, 2022 at 10:43:02
turn_on Lucht afzuiging
turn_on Lucht toevoer
2 seconds later
notify undefined
Finished at August 31, 2022 at 10:43:04 (runtime: 2.15 seconds)
this:
entity_id: automation.luchtverversing_aan_temp_hum_2
state: 'on'
attributes:
last_triggered: '2022-08-31T08:40:22.068397+00:00'
mode: restart
current: 0
id: '1661884888341'
friendly_name: Luchtverversing AAN (Temp/Hum) (Template)
last_changed: '2022-08-30T19:58:50.555577+00:00'
last_updated: '2022-08-31T08:40:22.109038+00:00'
context:
id: 01GBSGXZ9KNENGSQRTJRJ9N2MW
parent_id: 01GBSGXZ91E2WN1CZEDH6Z9W5Q
user_id: null
trigger:
platform: template
entity_id: sensor.werk_temp
from_state:
entity_id: sensor.werk_temp
state: unavailable
attributes:
state_class: measurement
unit_of_measurement: °C
device_class: temperature
friendly_name: Werk Temp
last_changed: '2022-08-31T08:42:58.653725+00:00'
last_updated: '2022-08-31T08:42:58.653725+00:00'
context:
id: 01GBSH2R6XNY1N4EB133HV428J
parent_id: null
user_id: null
to_state:
entity_id: sensor.werk_temp
state: '24.2'
attributes:
state_class: measurement
unit_of_measurement: °C
device_class: temperature
friendly_name: Werk Temp
last_changed: '2022-08-31T08:43:02.549858+00:00'
last_updated: '2022-08-31T08:43:02.549858+00:00'
context:
id: 01GBSH2W0N4FMD6VRMH2XMD8JF
parent_id: null
user_id: null
id: '0'
idx: '0'
for: null
description: sensor.werk_temp via template
``
This is interesting.
Are these sensors often offline?
I never notice they are unavailable.
I have an entity card with all the temp sensors on my home page to visually monitor this, so that I should maybe move my esp32’s to another spot if entities will get unavailable.
But I’m not always looking at this screen, so it could be.
Is there some test I can do that runs in the background for a set time, where I can see in a log if there’s a time where it’s offline?
You could probably use the ‘{{ trigger.to_state != unavailable}}’
And on the from states, as condition in the automation.
But I believe, someone please correct me if I’m wrong, the previous automation we had with two triggers and two conditions does not trigger on unavailable.
Perhaps it’s easier to just use that automation
You could probably use the ‘{{ trigger.to_state != unavailable}}’
And on the from states, as condition in the automation.
I’m not sure what you mean or how I can use this information.
But I believe, someone please correct me if I’m wrong, the previous automation we had with two triggers and two conditions does not trigger on unavailable.
Perhaps it’s easier to just use that automation
Do you mean this one?
condition:
- condition: numeric_state
entity_id: sensor.werk_humi
above: "{{ states('sensor.cp_humi') | float(0) }}"
- condition: numeric_state
entity_id: sensor.werk_temp
above: "{{ states('sensor.cp_temp') | float(0) }}"
Can I implement it like this?
alias: Luchtverversing AAN (Temp/Hum) (Template)
description: ""
trigger:
- platform: template
value_template: >-
{{ states('sensor.werk_temp') | float(0) > states('sensor.cp_temp') |
float(0)
and states('sensor.werk_humi') | float(0) > states('sensor.cp_humi') | float(0) }}
condition:
- condition: numeric_state
entity_id: sensor.werk_humi
above: "{{ states('sensor.cp_humi') | float(0) }}"
- condition: numeric_state
entity_id: sensor.werk_temp
above: "{{ states('sensor.cp_temp') | float(0) }}"
action:
- type: turn_on
device_id: 102103dc3ec38e21c9c878478ca2bde0
entity_id: switch.droger_stopcontact
domain: switch
- type: turn_on
device_id: 58913d5702500b426a217c63eb1b979d
entity_id: switch.lucht_toevoer
domain: switch
- device_id: 665e1de5daaaedefd9e0e553a5b0249e
domain: mobile_app
type: notify
message: Luchtverversing AAN (Temp/Hum) (Template)
mode: restart
I meant both the triggers and the conditions.