Tasmota switch restarting gives false positive in Automation

Hello community a fresh HA user here.

I have these NOUS A1T Tasmota flashed switches for which I have an Automation set up on the Current Power to send my phone a notification whenever it gets below a certain threshold.

Now this is working as intended but somehow the switch always restart once a day between 19:00 and 20:00 and this somehow gives a false positive for the Automation to trigger. That is because the Current Power gets set to undefined.

I’ve tried a numeric state and a Device trigger, but both keep getting a false positive when the device restart. Is there a way to only trigger the automation if the given value get below said threshold while ignoring the device restart?

Until now I have only used the frontend automation editor and haven’t dabbled in yaml configuration.

I followed this video to set up the switches and HA if that helps.

What I sometimes do is use a template trigger with a “for” clause. So you can set it to wait for the condition to be true for 1 minute.

If I understand correctly the “for” clause will help the temporary switch from 0 to undefined to be ignored? I will definitely give this a go when I get home.

It can or you can create a template that does not trigger on undefined state.

Give those a try and if needed post your automation.

Add a condition that the from_state isn’t undefined.

As you’ve not provided any details of the sensor, I can only guess that it’s an attribute of the switch. If so, something like:

condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes['current_power'] not in ['unknown', 'undefined'] }}"

should stop false positives of a transition from undefined to a number.

If you need any more help, please post the YAML of your current automation.

Here is my YAML of one of tthe automations:

- id: '1701256232862'
  alias: Droger
  description: ''
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.garage_droger_energy_power
    below: 5
  condition: []
  action:
  - device_id: 992757a119feee7bfd82572a6009ef40
    domain: mobile_app
    type: notify
    message: "\U0001F32C️ Droger is klaar \U0001F44D"
  - device_id: 43b2ebde334bed21f9f889362ade4e94
    domain: mobile_app
    type: notify
    message: "\U0001F32C️ Droger is klaar \U0001F44D"
    enabled: true
  mode: single

Should I then formulate the condition as follows, or what is the attribute in this case?

- condition: template
    value_template: "{{ trigger.from_state.attributes['sensor.garage_droger_energy_power'] not in ['unknown', 'undefined'] }}"
- id: '1701256232862'
  alias: Droger
  description: ''
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.garage_droger_energy_power
    below: 5
  condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes['sensor.garage_droger_energy_power'] not in ['unknown', 'undefined'] }}"
  action:
  - device_id: 992757a119feee7bfd82572a6009ef40
    domain: mobile_app
    type: notify
    message: "\U0001F32C️ Droger is klaar \U0001F44D"
  - device_id: 43b2ebde334bed21f9f889362ade4e94
    domain: mobile_app
    type: notify
    message: "\U0001F32C️ Droger is klaar \U0001F44D"
    enabled: true
  mode: single

Thanks, that’s simpler than I thought. I will give it a go :slight_smile:

So that didn’t work and found this piece of code and integration to find the former value. The previous state was Unavailable. So I will give that a go tomorrow.

Also just setting a condition that return false will still perform the action of automation is triggered. How?

condition: template
value_template: "{{ 0 }}"

Triggered by the trigger block or run manually? When you run the automation manually, the condition block is ignored — only the action is run.

Yeah I triggered it manually. I wish there would be an easier way to test this, the false positive happens somewhere between 19.00 and 20.00.

Im also trying to get a helper template to return the previous state but it’s not working right now.

state_attr('sensor.garage_droger_energy_power')

One thing I noticed from the SQL is that the dashboard widget returns Unavailable while clicking through to the attributes reveals unavailable so now I included both in the array.

I also read in the state docs I could check on is not none, so I should add that to the mix as well.

Small update: no luck as of yet. I tried

{{ trigger.from_state.attributes['sensor.garage_wasmachine_energy_power'] not in ['unknown', 'Unknown', 'undefined', 'Undefined', 'unavailable', 'Unavailable'] }}

And

{{ trigger.from_state.attributes['sensor.garage_droger_energy_power'] is not none }}

But the action (notification) is still send.

I tried setting an SQL query as stated before to get the previous value (see screenshot). Not sure what to do/try next.

In the end the solution was to create an input_boolean helper and set it to true when power gets above threshold. Then use the input_boolean as the condition for the notification automation and set the input_boolean back to false when triggered.