I have a simple automation that turns on ventilation in the bathroom if humidity exceed 80% and turn if off again when humidity get below 60%. Now I want to extend my script so the wait trigger for turning off the ventilator using a variable value ‘target_humidity’. the value of the ‘target_humidity’ variable is set as livingroom.humidity +5%
The code is as follows;
I understand that I must create a variable but the syntax is unknown for me. In the graphic editor I can select the name of the device but in the YAML it is a device ID of some sort.
I am an experienced C# developer but in HA I am a beginner. I assume that I can replace the line below: 60 with something like below: {{ target_humidity }} but maybe variables is not supported here …
Any help or pointers to examples to use is highly appreciated. Thanks
You have the right idea but Device Triggers don’t support templates.
Use a Numeric State Trigger but even that doesn’t support templating the above and below options. However, it will accept the name of a sensor or input_number entity.
Thanks to @Stiltjack and @Taras for pointing me to Numeric State Trigger, and I now can reference another sensor as below value. As you wrote it does not support templates so I assume that equal variables. The code now looks like the following;
alias: Lille bad ventilationstyring
description: Start udsugning hvis luftfugtigheden bliver for høj
trigger:
- platform: numeric_state
entity_id: sensor.0x00124b0022cea1b0_humidity
above: 80
condition: []
action:
- type: turn_on
device_id: 40fa08d6508457bb4d2bcc3c6c5b7d25
entity_id: switch.0x540f57fffefc3903
domain: switch
- wait_for_trigger:
- platform: numeric_state
entity_id: sensor.0x00124b0022cea1b0_humidity
for:
hours: 0
minutes: 2
seconds: 0
below: sensor.0x00124b0022ce9963_humidity
timeout:
hours: 1
minutes: 0
seconds: 0
milliseconds: 0
- type: turn_off
device_id: 40fa08d6508457bb4d2bcc3c6c5b7d25
entity_id: switch.0x540f57fffefc3903
domain: switch
mode: single
The sensor reference is still a device like ID and not the logical name as selected in the graphical editor … strange
So, if I need to offset the below humidity with the sensor value +5%, I cannot do this in HA. I need to use another tool like NodeRed to obtain this logic?