I am still inexperienced with writing automations and require help:
I have a dishwasher that is connect to a smart plug with power-meter and I want to turn it off automatically, because it uses up to 10W in standby. (Which is insane!)
I have defined this template sensor to define a state sensor with status standby in configuration.yaml:
I have confirmed that the sensor-status is correctly reported in the HA GUI depending on the dishwasher power-usage.
I defined the following automation for turning the dishwasher off, if it is in status standby for 30 minutes.
But it is not triggering for some reason and I do not understand why:
The entity id in your sensor and automation probably does not match. While I have no idea what the actual entity id for your sensor is (as it can be changed from the UI), the one that would be autogenerated from this name has two underscores after “kueche” while the entity id specified in the automation has one.
Thanks for suggesting this. I checked in the HA GUI and the entity id is reported as
sensor.kueche_spuelmaschine_status
So that should not be the issue.
I usually use the double underscores in the names for clear separation, which HA converts to single underscore for entity ids. (I believe because double underscore is not valid for variable names yaml(?))
This was part of the solution, so I accept it as solution. Thank you!
I messed this up: It was supposed to be 30 minutes.
Additionally, I also found that the smart plug was not reporting the change in power-consumption reliably. This was because the reporting-settings shown Zigbee2MQTT were to coarse, so that it would not report a change with a Delta >5 Watts.
This worked, when the dish-washer was in actually running and then went to standby (after finishing the cleaning) - this reported a status change for the template sensor. But it the smart-plug did not report a change in power consumption (and hence did not trigger the template sensor and automation) while testing, because there I just turned on the smart-plug (i.e. going from off to standby). In that case the Delta is below 5 Watts and hence the smart-plug did not update the power-consumption to a value >0W and hence the power-status of the template-sensor was not updated. (I hope this explanation is somewhat comprehensible.)
I now changed this and it now works as expected. (Testing is ongoing.)
Thanks for the reply. Yes, the null had also caught my attention. I created the automation in GUI, where the source-state is set to ANY. This corresponds to the null value in YAML.
I chose ANY for source-state, because I want the automation to trigger, whenever the machine status goes to standby and the template-sensor has two potential source-states for that (off and on). (The trigger does not have null state.)