So after reading quite a few posts I was able to get the switch for the Sonoff POW to turn off when a value below a certain number was recorded. My problem is I can’t add a “for” attribute into the automation because the platform is of type “template”.
I want the reading to be below a certain value for a specified time, and then the device must turn off and on. Here is what I have and it works, but not the “for a certain time part”
- alias: If Fridge Power Bellow 300W Turn Off and On
hide_entity: False
trigger:
platform: template
value_template: "{{ states.sensor.Fridge_Voltage.state | int < 300 }}"
action:
- service: switch.turn_off
entity_id: switch.Fridge
- delay: 00:00:10
- service: switch.turn_on
entity_id: switch.Fridge
If I’m understanding this correctly, you want to watch if the fridge goes below 300W for a specified period of time, then quickly turn off and back on.
Try adding this sensor in addition to the one you have:
sensor:
platform: template
fridge_volt:
value_template: '{{ states.sensor.fridge_voltage.state | int }}'
and then your automation would be this:
- alias: If Fridge Power Bellow 300W Turn Off and On
hide_entity: False
trigger:
platform: state
entity_id: sensor.fridge_volt
below: 300
for:
minutes: 10
seconds: 0
action:
- service: switch.turn_off
entity_id: switch.fridge
- delay: '00:00:10'
- service: switch.turn_on
entity_id: switch.fridge
Let’s make a few modifications then. I think the problem could be a combination of things so let’s add another trigger. If you restart HA while the watt is under 300 it probably won’t trigger because it’s looking for it to be above to begin with and then go below. So let’s fix that with another trigger and a condition. Then we will turn this automation on by default. Finally, the delay may need quotes. So try this:
Not really related to your original question, but you are only monitoring voltage correct? Your voltage won’t/shouldn’t ever change unless you had a power outage, so I don’t see how this automation would ever trigger. It appears you want to be monitoring power, which would be measured in watts (not volts).
Maybe I’m not understanding what you are trying to do?
Message | Unit | Description
----------|------|-----------------------------------------------------
Yesterday | kWh | Total Energy usage between 00:00 and 24:00 yesterday
Today | kWh | Total Energy usage today from 00:00 until now
Period | Wh | Energy usage between previous message and now
Power | W | Current power load
Factor | | The ratio of the real power flowing to the load to
| | the apparent power in the circuit
Voltage | V | Current line voltage
Current | A | Current line current
@HellfireZA: You probably want to interrogate the Power value instead of Voltage to see if your appliance is running or not. Otherwise you may constantly restart your fridge because the voltage will never go above 230V
Sorry for the confusion on the naming guys, initially I was going to test with Watt draw but the test POW I’m using has nothing connected to it at all so the W is always 0. The Voltage does change slightly between 233-240, so decided to use that since once I’ve got that right I can implement with correct values. So ignore the name, and know that I’m working with voltage here. As mentioned at the top, I did get it working but without the time lapse.
All code added and no errors:
Couple of things, the delay definitely works without the " because when I manually trigger the automation the delay occurs.
I’ve just tried it now, when I restart HA it triggers the automation immediately.
I guess that is because of this section:
platform: homeassistant
event: start
condition:
condition: template
value_template: “{{ states.sensor.fridge_voltage.state | int < 300 }}”
Yes, that’s correct. The trigger on homeassistant start and a condition that it’s < 300 was needed for testing since if the sensor is reporting 229 it would have to go above 300 first then below to trigger if we didn’t have it in there. You may just want to leave it, its up to you. But I wanted to make sure the automation was indeed working.
@Jer78 do you have any other suggestions I could try to get the timing to work please. As I said in my top post, I can get the automaton to at least work like that,
As in the part of the automation were “for” is included doesn’t work. The only time the automation triggers is when I restart home assistant, it doesn’t activate again after that, even when the value changes.