Hi,
I am new in Home Assistant and I want to control a fan with automation for 1 hour every day at a specific time.
I mean the fan should be ON at 17:00 every day then turned automatically OFF 1 hour later.
I tried to use UI editor but failed to set.
Hi, welcome to the forum!
Can you show your automation by posting the YAML code here as preformatted text (the </> sign in the toolbar)
Hi Nick,
I have set this two separate automation without using the delay function, but for some reason it is unreliable, so I would like to see a code with delay function.
- id: '1718646005425'
alias: Skirting Fan On
description: 'Skirting Fan ON'
trigger:
- platform: time
at: '12:15:00'
enabled: true
condition: []
action:
- type: turn_on
device_id: 468a933497661139271efd7067125378
entity_id: 7188ca727e4e421c1bd22e04bf01c0a4
domain: light
mode: single
- id: '1718645623232'
alias: Skirting Fan Off
description: ''
trigger:
- platform: time
at: '13:16:00'
enabled: true
condition: []
action:
- type: turn_off
device_id: 468a933497661139271efd7067125378
entity_id: 7188ca727e4e421c1bd22e04bf01c0a4
domain: light
mode: single
I have seen this code and wanted to implement but failed:
- alias: turn on fans
trigger:
platform: time
# You can also match on interval. This will match every 5 minutes
minutes: '/5'
seconds: 00
action:
- service: switch.turn_on
entity_id: switch.greenhousefan
- delay:
# supports milliseconds, seconds, minutes, hours, days
minutes: 1
- service: switch.turn_off
entity_id: switch.greehousefan
- You are turning on a light - is that a test or example?
- How did you get that
action:
- type: turn_on
AFAIK This should be (for a light)
action:
- service: light.turn_on
- If you want to test an automation to see if the action and conditions work, you can do that with a script which you trigger manually.
Have a look at The Home Assistant Cookbook â Automations
Sorry, but I donât now what you mean.
Do you mean it is not possible to make a code with using the delay function as you can see the last code that was made someone else here?
sorry for my bad English!
Your English is OK
Again: you are trying to turn on a light, not a fan.
And, how did you get that:
action:
- type: turn_on
The example you are showing is triggering every 5 minutes, itâs not a delay function.
Your time trigger is correct, you can see in the traces (right-top side in the automation what has happened with your automation)
This is an example I just created:
alias: "test: turn on light at time"
description: ""
trigger:
- platform: time
at: "whatever time you want"
condition: []
action:
- service: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.hall
mode: single
EDIT: you can solve your âdelayâ in multiple ways.
- Create 2 different automations, 1 for on, 1 for off
- In 1 automation, 2 time triggers, 1 for on, 1 for off (preferred way)
- In 1 automation, 3 actions, 1 for on, 1 delay, 1 for off
This is a working example with the âdelayâ:
alias: "test: turn on/off light at time"
description: ""
trigger:
- platform: time
at: "12:15:00"
id: "on"
- platform: time
at: "13:16:00"
id: "off"
condition: []
action:
- service: light.turn_{{ trigger.id }} # If switch entity, 'switch.turn_{{ trigger.id }}'
metadata: {}
data: {}
target:
entity_id: light.hall # Replace with the entity id of your light/switch/...
mode: single
I am using a sonoff zigbee mini relay for switching the fan and would like to make a simple code.
that is the plan but I have no idea how to get it.
alias: "Turn On Fans at time 19:00:00 for 1 hour"
description: ""
trigger:
- platform: time
at: "19:00:00"
condition: []
action:
- service: switch.turn_on
entity_id: 7188ca727e4e421c1bd22e04bf01c0a4
- delay:
hour: 1
- service: switch.turn_off
entity_id: 7188ca727e4e421c1bd22e04bf01c0a4
Are you using the webUI to create your automation?
There are errors in your code regarding indentation!
Also, itâs useful if you answer the questions since they are relevant to your problem.
But, apparantly you are using the right syntax now, with errors.
Pro tip: to break up your automation/problem into pieces so you know what is not right, use a script.
Correction: you have errors like âhourâ instead of âhoursâ
Like your on/off in one automation. Simpler than one automation for each.
Also a good idea to use the entity name for the entity_id instead of the meaningless alphanumeric.
Sorry, but I didnât see the question.
So I have created this code, could you please check that?
alias: "Turn On Fans at time 19:00:00 for 1 hour"
description: ""
trigger:
- platform: time
at: "19:00:00"
condition: []
action:
- type: turn_on
entity_id: 7188ca727e4e421c1bd22e04bf01c0a4
- delay:
hours: 1
- type: turn_off
entity_id: 7188ca727e4e421c1bd22e04bf01c0a4
Hi Ellcon,
can I change the name of the entity?
You are not making it easy to help you:
This example cannot work because of wrong indentation.
For the entity_id, if you start typing âswitch.â the yaml editor will show a list of available entities.
I have an automation to turn some room lights on at 4:30PM and off at 9:30PM. I was using separate automations for ON and OFF but from Nik4âs example I have now combined into one automation.
alias: Lamps
description: ""
trigger:
- platform: time
at: "16:30:00"
id: "on"
- platform: time
at: "21:30:00"
id: "off"
condition: []
action:
- service: switch.turn_{{ trigger.id }}
metadata: {}
data: {}
target:
entity_id: switch.e27_lamp1_relay
- service: switch.turn_{{ trigger.id }}
metadata: {}
data: {}
target:
entity_id: switch.athom_plug3_relay
mode: single
Thanks for your answer.
I am using a Zigbee switch from Sonoff (Sonoff ZBMINI) to switch a fan.
I have successfully added it to Home Assistant via ZHA.
After adding Sonoff ZBMINI = 01MINIZB to ZHA, the entity is classified as a light.
This device is not a light, but a switch (relay).
It does not seem possible to change the domain of an entity from light to switch as the âlightâ word is greyed out.
So, the switch is incorrectly classified as a light, as you can see the attachment.
I am using few other zigbee minis with the same (light) classified entity.
The first time, I used the webUI to create two separate automations which was unreliable (the relay stayed On few times), that is why I wanted to write a reliable code in yaml.
Hi Ellcon,
Thank you for sharing your code, this would be the solution for my problem, but it still not working for some reason.
I am using a Zigbee relay from Sonoff (Sonoff ZBMINI) to switch a fan.
I have successfully added it to Home Assistant via ZHA.
After adding Sonoff ZBMINI = 01MINIZB to ZHA, the entity is classified as a light.
This device is not a light, but a switch (relay).
It does not seem possible to change the domain of an entity from light to switch as the âlightâ word is greyed out.
So, the switch is incorrectly classified as a light, as you can see the attachment.
I also have more zigbee minis with the same âlightâ entity.
here you can see my rewrite code that is error free but still not working probably due to the wrong entity.
- id: '6666'
alias: Turn On Fans at time 10:00 for 1 hour
description: ''
trigger:
- platform: time
at: '10:00:00'
id: 'on'
- platform: time
at: '11:00:00'
id: 'off'
condition: []
action:
- service: switch.turn_{{ trigger.id }}
metadata: {}
data: {}
target:
entity_id: light.skirting_fan
mode: single
light.turn_{{ trigger.id }}
Hi Francisp,
that is the solution!
thank you for your help!
Yes, I used âswitch.â in my example but your devices may be setup differently. It was just to show that HA does give a list of valid entities while typing yaml.