Doubts regarding automation and trigger

I have a doubt regarding automation or better regarding the trigger part of an automation

The following automation should turn on the dehumidifier when the humidity is more that 63% in the time fram 7AM - 10PM.

- alias: "Accendi Deumidificatore Zona Notte"
  trigger:
    platform: numeric_state
    entity_id: sensor.humidity_158d00022c9a27
    value_template: '{{ states.sensor.downstair_humidity.attributes.max_value }}'
    above: 63
  condition:
    - condition: time
      after: '07:00:00'
      before: '22:00:00'
    - condition: state
      entity_id: input_boolean.automation_enabled
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.deumidificatore_sean_on
    - service: notify.stefano
      data:
        message: 'Deumidificatore Zona Notte Acceso'

Now lets take a look at the following scenario

let’s say that at 6AM the humidity will be 70% and it will stay constant till 10AM and then it will rise to 72%

when will the above automation kick in? At 7AM (Remember the humidity hasn’t changed from 6AM) or After 10AM when the humitity changes (trigger activated?).

Thanks

Stefano

Numeric state only triggers when the value crosses the threshold, so it will not trigger at all.

Thanks

Then I’ll have to find another way to trigger my dehumidifier.

You could try something like this:

- alias: "Accendi Deumidificatore Zona Notte"
  trigger:
    platform: state
    entity_id: sensor.humidity_158d00022c9a27
  condition:
    - condition: state
      entity_id: sensor.humidity_158d00022c9a27
      above: '63'
    - condition: time
      after: '07:00:00'
      before: '22:00:00'
    - condition: state
      entity_id: input_boolean.automation_enabled
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.deumidificatore_sean_on
    - service: notify.stefano
      data:
        message: 'Deumidificatore Zona Notte Acceso'

That way as soon as the humidity sensor value changes (either up or down) and the humidity sensor is above 63, it’s after 7am and the boolean is on it should trigger. Basically it’s looking for every change in state of the sensor then deciding to run the action or not based on the conditions.

So if the humidity is 70% at 6am and then at 10am it goes to 69% or 71% it should trigger the automation.

You’ll have to work out which sensors you want to look at but the basic code should work the way you want. I think…

1 Like

Does doing this fill the logs with “automation triggered” events?

That’s a cool idea, but still the humidity sensor will need to change for the automation to fire, right? So taking into consideration the scenario from my opening post the automation would not execute before 10AM.

I really don’t know but if it’s the only way to get what he wants then it’s something that might be unavoidable.

Oh, OK. I didn’t realize you wanted it to fire at 7 or when the humidity goes above 63.

then just add a time trigger of 7am.

- alias: "Accendi Deumidificatore Zona Notte"
  trigger:
    - platform: state
      entity_id: sensor.humidity_158d00022c9a27
    - platform: time
      hours: 07
      minutes: 00
      seconds: 00
  condition:
    - condition: state
      entity_id: sensor.humidity_158d00022c9a27
      above: '63'
    - condition: time
      after: '07:00:00'
      before: '22:00:00'
    - condition: state
      entity_id: input_boolean.automation_enabled
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.deumidificatore_sean_on
    - service: notify.stefano
      data:
        message: 'Deumidificatore Zona Notte Acceso'

then if the humidity is above 63 at 7am it will trigger and if its not the as soon as it goes above 63 after 7 am it will trigger then.

1 Like

Yeah… as @finity wrote

Much Love :smile:

1 Like

I don’t know if you noticed but I edited my post above to change the format of the time trigger.

I can’t remember if it will work the way I originally wrote it or not.

I know the edit will work.

@finity one thing are you sure it’s condition: state

  condition:
    - condition: state
      entity_id: sensor.humidity_158d00022c9a27
      above: '63'

shouldn’t it be condition: numeric_state

  condition:
    - condition: numeric_state
      entity_id: sensor.humidity_158d00022c9a27
      above: '63'

You may be right. Try it and see which one works.