I am a huge fan of HA but also its community forum. I found so many answers here that I never really had a need to raise a question. Kudos to all of you
However, I am now experiencing an issue with HA and I couldnt really find anything in the forum. If there is already a topic on this issue, feel free to point me to it.
I have a sensor that enters multiple times the same state and this, of course, alters the behavior of some automation.
The sensor holds a state calculated from a Tasmota device power usage. The tasmota device is MQTT powered and I know that sometimes, it has some trouble to reach my wifi. In this case, I would have expected to see the state going from “running” to “unvailable” and back to “running” which is an expected behavior but that is not the case here.
The code associated for this sensor is
name: washing machine
unique_id: washing_machine_state
icon: mdi:washing-machine
availability: >
{{ states('sensor.switch_washingmachine_energy_apparentpower') not in ["unknown", "unavailable"] }}
state: >-
{% if states('sensor.switch_washingmachine_energy_apparentpower') | int > 20 %}
running
{% elif states('sensor.switch_washingmachine_energy_apparentpower') | int > 0 %}
powered
{% elif is_state('switch.switch_washing_machine', 'off') %}
on hold
{% else %}
off
{% endif %}
I am not sure this is an issue so much as the sensor simply updating itself, although its not ideal behaviour.
It should in theory not affect automations / triggers if the state is reported as being the same each time, do you have an example of an automation that is being affected by this behaviour as it may be simpler to correct the automation to prevent issues maybe ?
- id: '1657108578849'
alias: washing machine on hold in peak hours
description: ''
trigger:
- platform: state
entity_id:
- sensor.washing_machine
to: running
for:
hours: 0
minutes: 1
seconds: 0
condition:
- condition: state
entity_id: binary_sensor.cheapest_hours
state: 'off'
action:
- type: turn_off
device_id: c9a426c0d317046d3e364e55d847c964
entity_id: switch.switch_washing_machine
domain: switch
mode: single
So whenever the state turns in “Running” for a minute (and the electricity prices are high), then I turn the machine off.
The issue is that, when a washing machine is running and we enter the “non cheap hours”, I would like the cycle to continue running until the end.
Now that I have written this, I should probably debug what actually triggered the automation. That could well be the change in “cheapest hours” sensor.
So, replying to my own investigation, I am unsure as to what triggered the automation to kick in again.
The below screenshot indicates that the washing_machine sensor is the one triggering the automation (used as trigger in automation), although, we can clearly see that the “cheapest_hours” sensor (used in condition only) turned off.
Digging a bit deeper, the state of the waching machine entity didnt change around 4PM and should not have triggered the automation.
(image follows in new comments since I am a new user and I am restricted for now)
So, I am truly unsure of what is going on here.
On the one hand, I see the same state being recorded again in HA (potentially triggering the automation).
On the other hand, I see that the only thing that changed was the state of a sensor used in “condition” in the automation.
Well well well, if anyone has any pointers as to what and how to debug that, that would be appreciated
Ok, understood. Although I am no expert but I do believe the state changing (or in this case not changing) from running to running, you could try adding a not_from:
- platform: state
entity_id:
- sensor.washing_machine
to: running
not_from: running
for:
hours: 0
minutes: 1
seconds: 0
Might work but shouldn’t do any harm either way!
Your automation triggers on each change in the power usage registered.
In order to prevent this then make an if then around each of your state set lines.
I see what you mean and thanks for your suggestion. However, I would have liked Home Assistant to filter out the state returned by my calculation since this is the same state. Is that not possible?
I guess there is a timestamp or id on your updates and that will change with each update.
It might he hidden, but it is probably there.
You might be able to change the trigger, so it trigger on passing the value and not with every value above the limit.
I am not enough into HA to know that by memory and I can not look up the documentation here.
Some of the gurus will know this by had and provide the answer.