#Toggle smartplug when value out of range

1 messages · Page 1 of 1 (latest)

sharp haven
#

Hi.

I have a humidity sensor and a dumb humidifier plugged into a zigbee smartplug.

I would like to turn the plug on when below 40% and off when above 50%. Should i make 2 automations for this or is a single one possible?
Or are there better ways to control this?

gloomy cove
#

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

opal vigil
#

one automation, trigger on both states and HA restart.

sharp haven
#

So in this case would this be a switch statement if this do that, if that do this?

gloomy cove
sharp haven
#

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%

queen creekBOT
#

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.

gloomy cove
#

@sharp haven please format your message as described above

snow fog
#
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.

opal vigil
#

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.