Automation/ numeric_state issue

Hello,

I have an automation which turns on a pump when moisture value is below 40. However reading through threads I’ve come to the loose understanding an automation doesn’t fire if the value is already below the stated amount ( I think)? How would I go about relieving such an issue when the time conditions are met but the moisture value is already below 40 when the automation is supposed to trigger.

Any help would be appreciated, thank you.

alias: ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.average_moisture
    below: '40'
  - platform: time
    at: '21:00:01'
condition:
  - condition: time
    after: '21:00:00'
    before: '12:00:00'
  - condition: numeric_state
    entity_id: sensor.average_moisture
    below: '40'
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.sonoff_pump
  - device_id: 7dc7b4792c37609d4b68e7bb68201d56
    domain: mobile_app
    type: notify
    message: System On
    title: 'System On '
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.sonoff_pump
  - device_id: 7dc7b4792c37609d4b68e7bb68201d56
    domain: mobile_app
    type: notify
    message: System Off
    title: System Off
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
mode: single

If you want it to turn on any time the moisture is below 40 or at 9pm just remove the conditions.

alias: ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.average_moisture
    below: '40'
  - platform: time
    at: '21:00:01'
action:
  - service: switch.turn_on
    etc...

If you only want it to turn on between 9pm and midday the next day when the moisture is below 40, then what you have is nearly correct. Just change the trigger to this:

alias: ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.average_moisture
    to:
condition:
  - condition: time
    after: '21:00:00'
    before: '12:00:00'
  - condition: numeric_state
    entity_id: sensor.average_moisture
    below: '40'
action:
action:
  - service: switch.turn_on
    etc...

This will trigger on any state change of the moisture sensor then check the conditions, both of which must be true for the actions to occur.

You can also throw in an automation reload and home assistant restart trigger in case the sensor changes to below 40 while these are occurring:

trigger:
  - platform: numeric_state
    entity_id: sensor.average_moisture
    to:
  - platform: homeassistant
    event: start
  - platform: event
    event_type:
      - automation_reloaded
1 Like

Hi Tom,

Thank you for the quick response. I am attempting to change the trigger: based on the second example you’ve given which is

trigger:
  - platform: numeric_state
    entity_id: sensor.average_moisture
    to:

Im however getting the error Message malformed: extra keys not allowed @ data['to'] am I missing something? thanks

Sorry that should be:

trigger:
  - platform: state
    entity_id: sensor.average_moisture
    to:

FYI: leaving out the null to: will trigger on any attribute or state change, you don’t want that you only want state changes.

Understood! That makes sense. I’ve made the appropriate changes and will report back on the results. Once again I appreciate your help.