I do have electric kettle connected to Aeotec smart switch (a z-wave wall plug). As for now im turning the kettle (by the switch) on and off manualy, from the ios app, but i would like to create automation to turn off the switch when boiling is done (kettle turns itself off after boiling, but i would prefer to not leave it “under power” - just for safety reasons).
There are two ways to do it:
Turn off the switch after x minutes after turning it on. Its easy way, lets say boiling takes 2 minutes, so hass can turn off the switch after 5 minutes after turning it on (manually by me). Problem: more water = longer boiling, less = shorter. So more elegant would be to make it in a bit more “smart” way.
Switch does check power consumption, so i could use it to know when boiling is done and kettle turned itself off. But theres one problem - raports about power consumption are sent every 30 seconds, so if i would do something like “if power < 1000 W, turn off the switch” it could turn itself during boiling, just because HASS didnt got yet a info about high power consumption.
Solution in this case could be something like this:
Turn off switch.kettle_switch if power < 1000 for 60 seconds.
Question is how to “build it” in correct way in home assistant ?
You can use a numeric state trigger with a time value, and a condition so it doesn’t turn off as soon as it’s on
automation:
- alias: 'Turn off an idle kettle'
trigger:
# When the kettle's power attribute is below 1000 for one minute
- platform: numeric_state
entity_id: switch.kettle
value_template: '{{ state.attributes.power|default(0)|int }}'
below: 1000
for:
minutes: 1
# Or it's simply been turned on and never used
- platform: state
entity_id: switch.kettle
to: 'on'
for:
minutes: 5
condition:
# And it has been on for at least 2 minutes
- condition: state
entity_id switch.kettle
state: 'on'
for:
minutes: 2
action:
# Turn it off
- service: switch.turn_off
entity_id: switch.kettle
Some extra question to understand everything.
In template {{ state.attributes.power|default(0)|int }} we are using “int” to convert value from float to integer, as i do remember only integers can be used so its understandable. But what actually “default(0)” does ?
default(0) says that if it doesn’t receive a value then it’s to use zero. For instance, if when the switch is off it doesn’t report power usage at all, then this will avoid you having an error.
Hello.
I am trying to make a similar automation, but for my dumb dishwasher:
After it turns on, if no power consumption during 7 minutes, it should turn off. This is what I have:
alias: Máquina de Lavar Loiça - Desligar se não lavar
description: Desligar a máquina da Loiça caso não haja consumo
trigger:
- platform: numeric_state
entity_id: sensor.localtuya_power_02_current_consumption
below: '5'
for: '00:07:30'
condition:
- condition: state
entity_id: switch.localtuya_power_02
state: 'on'
for: '00:07:00'
action:
- service: switch.turn_off
target:
entity_id: switch.localtuya_power_02
- service: notify.mobile_app_poco_f2_pro
data:
message: Não havia loiça para lavar.
title: Máquina de Lavar Loiça desligou.
mode: single
To test an automation there’s three stages you can follow. Testing the action, the condition and action, and the whole automation:
Use Configuration → Automations to find the automation and then push Run Actions. If this fails your problem is in the action: section, and details should be found in your log file
Use Developer tools → Services and call automation.trigger on the automation with skip_condition: false. If the first passes but this fails then the problem is in your condition: block
Use Developer tools → States to find the trigger entity, click the name, then change the state (at the top) to something that’ll trigger the automation before pushing Set State. If this fails then the problem is with your trigger: section, or the automation is turned off (you can check that in Developer tools → States).