Can't create Automation for Humidity Changes

I have a humidity sensor, and I want when RH goes above 58% or below 48%, it sends a notification. I have two different problems with the configuration below.

  1. For reasons I can’t understand, if on the “above” I set a value bigger than “2”, the automation disappears from the list in lovelace

  2. How can I pass the value of the humidity in the message?

 alias: Guitarra
 description: ''
 trigger:
   - type: humidity
     platform: device
     device_id: 03a607c75b0212e8607243fae86axxxx
     entity_id: sensor.humidity_158d0001e4c4f5
     domain: sensor
     above: 50
     below: 20
 condition: []
 action:>   - device_id: xxxx
     domain: mobile_app
     type: notify
     message: Test
     title: Test
 mode: single

Try this. Maybe the service has a different name. You can check it out under developer tools/services and set it exactly as it shows there.

- id: '2132345667233'
  alias: Guitarra
  trigger:
  - platform: numeric_state
    entity_id: sensor.humidity_158d0001e4c4f5
    above: 58
  - platform: numeric_state
    entity_id: sensor.humidity_158d0001e4c4f5
    below: 48
  action:
  - service: notify.mobile_app
    data:
      message: "La humedad es del {{trigger.to_state.state}}%"
      title: "La humedad es del {{trigger.to_state.state}}%"
1 Like

Hi,
Almost there. I’m using the below. My automation seems to persist but it’s not sent because of the message line (if I remove the dynamic part, it works).

What should I do?

image

alias: Controlo RH Guitarra
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.humidity_158d0001e4c4f5
    above: 58
  - platform: numeric_state
    entity_id: sensor.humidity_158d0001e4c4f5
    below: 48
condition: []
action:
  - device_id: e218275eaee44161976ae4a6baed6744
    domain: mobile_app
    type: notify
    message: "Humidade Guitarra é: {{trigger.to_state.state}}%"
    title: ''
mode: single

The automation will only trigger when it surpasses a threshold. If it goes from 59.2 to 60.1, it won’t trigger. Clicking EXECUTE in the UI won’t do it for this particular automation because the content of the message depends on the trigger information and EXECUTE ignores the trigger. To test if it works, go to developer tools/states and set a different state to sensor.humidity_158d0001e4c4f5 , for example, 55. Click set state, It should do nothing.

Then set another state (60 for example), it should trigger this time.

If it still doesn’t work, just copy and paste the action section from my example.

If after that it still doesn’t work, try replacing “data:” with “data_template:”, I believe it’s not necessary though.

Don’t forget to restart HA after every change in your configuration.yaml

1 Like

That’s it, it worked. thank you very much.

Will the “real” state revert back automatically?

1 Like

Yep, it will, as soon as the sensor sends another update.

1 Like

Just out of curiosity, why isn’t the device’s sensor “changes state” trigger working?

It’s advised here that the numeric_state should be used for the entity but why isn’t the device sensor working as a trigger?

I’m using the following code and it isn’t triggered at all. I’d like to trigger on each change and then check if the fan should be switched on or off.
If this simply isn’t working (yet) in HA then I think I’ll go for a time based automation.

alias: Bathroom - Fan control
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: 923cc77b0562e373b950d5207ee4535f
    entity_id: sensor.sensor_thermo_hygro_bathroom_humidity
    domain: sensor
    above: 0
condition: []
action:
  - choose:
      - conditions:
          - type: is_humidity
            condition: device
            device_id: 923cc77b0562e373b950d5207ee4535f
            entity_id: sensor.sensor_thermo_hygro_bathroom_humidity
            domain: sensor
            above: 70
        sequence:
          - service: script.bathroom_fan_on
    default:
      - service: script.bathroom_fan_off
  - service: notify.mobile_app_jory_s10
    data:
      message: Humidity change!
      title: Humidity change!
mode: single