I’m guessing I’m not the first one with this question but have trouble in looking for right solution from forums. Here is my problem: this summer I had a ZigBee plug that controlled pump for watering my plants. It happened several times that it didn’t execute the command and every time it was a problem for my plants. I have also noticed that I would like to have some kind of double check mechanism for our terrarium light. I’m not looking to improve ZigBee reliability (this is separate story) but just want to get notified when something is not working so I can manually fix it. I need something generic which I can apply to different devices. Here is logic that I would like to implement:
Define a variable “status” which will be used for compare the wanted state and actual state
if “status” is on and ZigBee plug is off then send a command to ZigBee plug to turn on the switch
If “status” is off and ZigBee plug is on then send a command to ZigBee plug to turn off the switch
A few seconds after previous commands execution:
4.1 If “status” is on but a) ZigBee plug reports power consumption different than e.g. 4W (detects that my pump is broken or disconnected etc) b) ZigBee plug doesn’t report anything (detecting that my ZigBee plug is gone bad) then raise notification (I already have setup Telegram group where I get messages for outstanding situations from my HA)
4.2 If “status” is off but ZigBee plug reports power consumption other than 0W then raise notification
I’m a bit confused on which one HA mechanism is most suitable for me (automation, blueprints, templates, scripts, …). It should be parametrized with selection of: on/off device, expected power range (min,max), a notification device and a text for notification.
Can you recommend me where to start from?
Well, blueprints are premade(by other community members or you) automations, scripts, or now templates. So your question is lacking a bit of background knowledge.
I don’t follow what you are looking for, but it is likely an automation. checking that something didn’t happen is not the most fun task to take on. You didn’t want to hear it, but adding a zigbee routing device between a solid part of the network and the outside device id likely what you need to happen,
Anyway…
I’m sure that can be done. Also having someone or something writing it for you means the second it misbehaves, you will be struggling back to find someone to fix it for you.
The best way to learn is to just try. Run thru the docs on getting started with the automation editor. If you get stuck, come back with what you have done.
Hi,
Thank you all for quick replies. Here is what I have build so far:
I have created Template Switch which turns on/off ZigBee plug and at the same time checks the power consumption. If the power consumption is out of expected range then a notification is being sent to my Telegram group.
This Template Switch is visible as entity in automation editor so I just add it to automation.
Template Switch is stored in configuration.yaml file and I need to duplicate that code for every ZigBee plug I want to use.
Is there a mechanism in Home Assistant where I can parametrize this e.g. to have something with parameters (switch entity, power sensor entity, expected power, notification) so I can have multiple instances without hardcoding it into configuration.yaml?
Thank you
Here is Template Switch from my description. Additional functionality in this example (with wait_template) which is not important for this topic is that as soon as I get power measurement I perform check instead of having fixed delay and then doing power measurement. In this way I get more responsive “template switch”…
switch:
- platform: template
switches:
svetlo_za_terarijum:
friendly_name: "Svetlo za terarijum"
icon_template: "mdi:tortoise"
turn_on:
- action: switch.turn_on
target:
entity_id:
- switch.terarijum
- wait_template: "{{states('sensor.terarijum_power')|int(default=0) > 10}}"
continue_on_timeout: true
timeout: "10"
- if:
- condition: template
value_template: "{{not(states('sensor.terarijum_power')|int(default=0) > 10)}}"
then:
- action: notify.alarm
data:
message: "Svetlo za kornjaču se nije uključilo!"
turn_off:
# need to find a way to detect if switch.terarium status is unknown
- action: switch.turn_off
target:
entity_id:
- switch.terarijum
- wait_template: "{{states('sensor.terarijum_power')|int(default=100) < 10}}"
continue_on_timeout: true
timeout: "10"
- if:
- condition: template
value_template: "{{not(states('sensor.terarijum_power')|int(default=100) < 10)}}"
then:
- action: notify.alarm
data:
message: "Svetlo za kornjaču se nije isključilo!"