I have installed Home Assistant on Raspberry Pi 4 2Gb. Installed AlexxIT/SonoffLAN
(GitHub - AlexxIT/SonoffLAN: Control Sonoff Devices with eWeLink (original) firmware over LAN and/or Cloud from Home Assistant). I can control my Sonoff 4CH (R2) through it.
I went through all this trouble to set up a loop timer for my aquarium fan which is installed on Sonoff 4CH. I do I set up the loop timer so that the fan will turn on for 2 hours and then be turned off for 1 hour and this cycle will be repeated 24x7.
You can do it easily with two automations.
trigger:
platform: state
entity_id: switch.fan
to: 'on'
for:
hours: 2
action:
service: switch.turn_off
entity_id: switch.fan
trigger:
platform: state
entity_id: switch.fan
to: 'off'
for:
hours: 1
action:
service: switch.turn_on
entity_id: switch.fan
Home Assistant restarts will reset the for timers though.
Thanks for the quick reply.
Fan on the switch called Heater + Filter. So I should use heater + filter in entity_id? and where do I add this code? (Noob here)
No. âHeater+Filterâ is the entityâs friendly_name
not its entity_id
.
Go to Configuration > Entities, find Heater+Filter and it will show you its entity_id
.
I suggest you review the basics for creating automations:
Entity name found
Can I change it to a user-friendly name?
@ tom_lâs script consist of a trigger and action. So where should I add it.
I went through the link, but I canât relate to it. It mentions a GUI based automation while this is a script.
The entity_id?
Yes, but there are rules.
- Any automation, script or group already using that entity_id will stop working if you change it. Sounds like you have not written any automations or scripts yet, so this is ok.
- The entity_id must have a specific format:
domain.object_id
You cant change the domain (in this case switch
) and the object_id part must only use lowercase letters, numbers, or underscores ( _
). No spaces, dashes, capital letters or other symbols.
So changing the entity_id to switch.heater_and_filter
is valid but switch.heater + filter
is not valid.
That was not a script. It was two automations (well the barest minimum parts of automations). Read the link 123 posted then go here and try adding an automation:
(then click the button in the bottom right corner âAdd Automationâ)
Solution found
Fan off code. this can be pasted in YAML, which can be accessed from the three dots menu. Just replace entity id with Sonoff entity id which is in format "switch.sonoff_xxxx_Y where XXX is your snoff device id and Y is the value of gang/switch.
to: represents the On or off state
For: is the time in format HH:MM:SS
alias: 'Fan On '
description: ''
trigger:
- platform: state
entity_id: switch.sonoff_XXXX_3
to: 'on'
for: '00:00:30'
action:
- service: switch.turn_off
entity_id: switch.sonoff_XXXXX_3
mode: single
I was 30sec on and 40sec off for experimental purposes. Just need to change the time value for both as required.
Great you worked out how to write an automation. Donât forget this warning though:
Without the support of you guys, I was just banging my head on the wall. The next plan is to use a graph to monitor this behaviour.
Immunity from restart is a challenge for another time.
One issue found.
How do I define time in mins or hour?
in HH:MM:SS if I input any value greater than 00:00:59 e.g 00:01:00 it doesnât work.
As per my original automations above is easiest:
Look what I wrote, then look what you wrote. They are not the same are they?
For was missing