Numeric Trigger going off when it shouldn't

I have a power meter that is connected to a washing machine. Whenever the power meter falls off the WiFi ti seems to trigger an automation which seems to be giving LOTS of false positives. I’m not sure how to fix this. It is causing a lot of angst in the house because this notification goes off several times when it shouldn’t be.

id: '1635815841325'
alias: State - Washing Machine
description: ''
trigger:
  - platform: numeric_state
    id: 'On'
    above: '5'
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
    entity_id: sensor.washing_machine_dryer_current_consumption
  - platform: numeric_state
    entity_id: sensor.washing_machine_dryer_current_consumption
    id: 'Off'
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
    below: '5'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'On'
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.washing_machine
      - conditions:
          - condition: trigger
            id: 'Off'
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.washing_machine
          - service: input_datetime.set_datetime
            target:
              entity_id: input_datetime.washing_machine_finished
            data:
              timestamp: '{{ now().timestamp() }}'
          - service: notify.mobile_app_denise_mobile
            data:
              message: The washing machine has finished
              title: Washing Machine
          - service: notify.mobile_app_nathaniel_mobile
            data:
              message: The washing machine has finished
              title: Washing Machine
    default: []
mode: single

When the Kasa tplink drops off the wifi, after 1 min it triggers the even that it’s gone under 5W when it never actually went over 5W when it went off line.

These two monitors sit next to each other and they went off at the same time:
image

Add conditions to exclude the trigger.to_state and trigger.from_state being 'unavailable'.

Is the state of “sensor.washing_machine_dryer_current_consumption” turning to “unavailable” when the wifi drops?

If so, you can add another condition with a trigger variable after the trigger condition

...
    - conditions:
        - condition: trigger
          id: 'Off'
        - condition: template
          value_template: "{{ trigger.from_state.state not in ['unavailable', 'unknown'] }}"
      sequence:
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.washing_machine
...

how do you do that?

I changed it to this:

action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'On'
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.washing_machine
      - conditions:
          - condition: trigger
            id: 'Off'
      - condition: "{{ trigger.from_state.state not in ['unavailable', 'unknown']}}"
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.washing_machine

and I seem to get the error message :

Message malformed: required key not provided @ data['action'][0]['choose'][1]['sequence']

Sorry, I’m on a tablet and the spacing got messed up when I pasted it… the new condition needs to line up with the original one… it’s fixed above.

haha the errors are getting longer:

Message malformed: Unexpected value for condition: '{{ trigger.from_state.state not in ['unavailable', 'unknown']}}'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['action'][0]['choose'][1]['conditions'][1]

I’m sorry, I messed up the shorthand notation of the template condition in the Choose action…

...
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'On'
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.washing_machine
      - conditions:
          - condition: trigger
            id: 'Off'
          - "{{ trigger.from_state.state not in ['unavailable', 'unknown']}}"
...

EDITED to remove misleading information and add shorthand notation resource. (Translation: I’m an idiot who read the docs, misunderstood the format, then blamed it on the Choose action… :sweat_smile:)

ok… that workes far better… cheers…now to see what it does when it falls off the WiFi

?

I almost always use shorthand notation in a choose’s conditions.

action:
  - choose:
      - conditions: "{{ trigger.id == 'On' }}"
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.washing_machine
      - conditions:
          - "{{ trigger.id == 'Off' }}"
          - "{{ trigger.from_state.state not in ['unavailable', 'unknown']}}"
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.washing_machine

I stand corrected… for some reason I was doing it like this (:man_facepalming:):

- conditions:
    - condition: trigger
      id: 'On'
    - condition: "{{ trigger.id == 'On' }}"