#Toggle smartplug when value out of range
1 messages · Page 1 of 1 (latest)
In my opinion a single one is way cleaner. The scenario you describe is rather simple. Trigger on any state change of the humidity sensor and check in the action section whether to turn the plug on or off
one automation, trigger on both states and HA restart.
So in this case would this be a switch statement if this do that, if that do this?
If/else or choose.
I'd go with choose
I came up with this after some googling:
alias: Humidity Control
description: Turns plug on, if humidifity is below 40%, off otherwise
triggers:
- entity_id:
- sensor.lumi_lumi_sensor_ht_agl02_humidity
attribute: humidity
above: 50
trigger: numeric_state
- entity_id:
- sensor.lumi_lumi_sensor_ht_agl02_humidity
attribute: humidity
below: 40
trigger: numeric_state
conditions: []
actions:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.lumi_lumi_sensor_ht_agl02_humidity
below: 40
sequence:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.third_reality_inc_3rspe01044bz
- conditions:
- condition: numeric_state
entity_id: sensor.lumi_lumi_sensor_ht_agl02_humidity
above: 50
sequence:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.third_reality_inc_3rspe01044bz
default:
- data: {}
entity_id: switch.third_reality_inc_3rspe01044bz
action: switch.turn_off
mode: single
But it semes like its not triggering. If i run the actions it turns on now that humidity is below 40%
To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.
@sharp haven please format your message as described above
alias: Humidity Control
description: Turns plug on if humidity is below 40%, off otherwise
triggers:
- trigger: numeric_state
id: humidity_above_50
entity_id:
- sensor.lumi_lumi_sensor_ht_agl02_humidity
attribute: humidity
above: 50
- trigger: numeric_state
id: humidity_below_40
entity_id:
- sensor.lumi_lumi_sensor_ht_agl02_humidity
attribute: humidity
below: 40
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id: humidity_below_40
sequence:
- action: switch.turn_on
target:
entity_id: switch.third_reality_inc_3rspe01044bz
data: {}
- conditions:
- condition: trigger
id: humidity_above_50
sequence:
- action: switch.turn_off
target:
entity_id: switch.third_reality_inc_3rspe01044bz
data: {}
default:
- action: switch.turn_off
target:
entity_id: switch.third_reality_inc_3rspe01044bz
data: {}
mode: single
Since you are having them triggered uniquely, the best way to do this is to utilize trigger IDs, and then check for which trigger actually fired by making the choose condition be literally "which trigger fired" instead of essentially repeating the trigger as the condition.
In a situation like this, having a guard set to home assistant power up is always handy. In this case adding a trigger for home assistant started and repeating the checks I think is the good strategy.
It depends on how this plug is important (safety?) of course.