Not_from with numeric state

hey, I’m familiar with the not_from state when defining moments where the state goes say to unavailable or unknown in a trigger, but how do you define this for a numeric state trigger ?

For example, today, I updated my Z-Wave JS UI addon (which makes the devices go offline for about 30 seconds), when the devices came back, it triggered this automation because the value was below 3.1 for 2:30 after the device came back online:

trigger:
  - type: power
    platform: device
    device_id: 4d008806cd3f0815b7c45579c71444de
    entity_id: sensor.smart_switch_7_electric_consumption_w
    domain: sensor
    below: 3.1
    for:
      hours: 0
      minutes: 2
      seconds: 30

for example, it does not accept if I place this below, in the above trigger information

    not_from:
      - unknown
      - unavailable

is there an equivalent for numeric state triggers?

1 Like

No there isn’t. It is for state triggers only.

You will have to use a template condition:

condition:
  - condition: template
    value_template: "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"

This will not catch the cases when the state does something like this: unknown2.302.31 for 2 minutes

3 Likes

thanks, @tom_l, i’m just a little confused as to where I place that condition, in the trigger or the general automation condition? to make it clear, this the entire automation:

alias: Washing Machine Status
description: For Washing Machine notification system
trigger:
  - type: power
    platform: device
    device_id: 4d008806cd3f0815b7c45579c71444de
    entity_id: sensor.smart_switch_7_electric_consumption_w
    domain: sensor
    below: 3.1
    for:
      hours: 0
      minutes: 2
      seconds: 30
  - type: power
    platform: device
    id: washing_started
    device_id: 4d008806cd3f0815b7c45579c71444de
    entity_id: sensor.smart_switch_7_electric_consumption_w
    domain: sensor
    above: 3.1
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition: []
action:
  - if:
      - condition: trigger
        id: washing_started
        alias: Washing Machine Started
    then:
      - service: zwave_js.set_config_parameter
        data:
          parameter: "21"
          value: "0"
        target:
          device_id: 4d008806cd3f0815b7c45579c71444de
      - service: zwave_js.set_config_parameter
        data:
          parameter: "23"
          value: "120"
        target:
          device_id: 4d008806cd3f0815b7c45579c71444de
      - service: input_datetime.set_datetime
        data:
          datetime: "{{ now() }}"
        target:
          entity_id: input_datetime.washing_machine_started
      - service: input_datetime.set_datetime
        data:
          datetime: >-
            {{ (now().timestamp() +
            states('input_number.washing_machine_expected_runtime') | float(0))
            | timestamp_local() }}
        target:
          entity_id: input_datetime.washing_machine_expected_time_to_stop
    else:
      - service: notify.mobile_app_sony_xperia_zx1
        data:
          message: Washing machine is done!
          title: Washing Machine Status
      - service: tts.cloud_say
        data:
          entity_id: media_player.fire_tablet
          message: The washing machine is done.
      - service: notify.mobile_app_iphone
        data:
          message: Washing machine is done!
          title: Washing Machine Status
      - service: input_datetime.set_datetime
        data:
          datetime: "{{ now() }}"
        target:
          entity_id: input_datetime.washing_machine_stopped
      - service: input_number.set_value
        data:
          value: >-
            {{ (as_timestamp(states('input_datetime.washing_machine_stopped')) -
            as_timestamp(states('input_datetime.washing_machine_started'))) |
            float(0) }}
        target:
          entity_id: input_number.washing_machine_expected_runtime
      - service: zwave_js.set_config_parameter
        data:
          parameter: "21"
          value: "1"
        target:
          device_id: 4d008806cd3f0815b7c45579c71444de
      - service: zwave_js.set_config_parameter
        data:
          parameter: "23"
          value: "0"
        target:
          device_id: 4d008806cd3f0815b7c45579c71444de
mode: single

Under the general condition block. Replace this:

With:

condition:
  - condition: template
    value_template: "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
2 Likes

got it, thank you!