I have a question whether this is possible or not. Currently I do have a lot of automation which is fine, but if I could cook some of them down to one
So here is what I want to accomplish:
When motion detection is turned on then:
- If between 00-06am
then do this
- Turn on light:
- light1
- light2
- Data:
Brightness: 20%
- if between 06 and sun is above horizon
then do this
- Turn on light:
- light1
- light2
- Data:
Brightness: 100%
- if between below horizon and 00pm
then do this
- Turn on light:
- light1
- light2
- Data:
Brightness: 50%
Or do I need to create 3 Automations in order to do this?
Hey mf_social,
Nice and thanks for the response. Seems to be running great!
I tried to modify it so I could run a script bases on the time, but no success.
Do you have an idea of how I should tweak the above if I wanted it to trigger 3 different scripts depending on the time?
I read some other forums where people says itâs best to use the conditions in the automation instead of in the script. I donât know whats best though.
Curious, so if I wanted to change the timing from 00 to 10pm, and only run another script during the âbelow horizonâ would I just have to change it like this?:
automation:
alias: lights to different brightnes
trigger:
platform: state
entity_id: MOTION_SENSOR
to: DETECT_MOTION
action:
service_template: >
{% if((now().hour <= 6) or (now().hour >= 22))}%} script.ONE
{% else %} is_state('sun.sun' , 'below_horizon') {% endif %} script.TWO
Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token â)â, got â:â) for dictionary value @ data[âactionâ][0][âdata_templateâ][âentity_idâ]. Got None. (See /config/configuration.yaml, line 17). Please check the docs at Automation - Home Assistant
You keep changing what you want to get out of this automation, and I donât really know why.
The reason I added conditions to the third one is because otherwise there are times in the day that would not be resolved by the template. Each variation you have asked for is actually completely different, the first required templated optional data keys that were resolvable 100% of the time, the second required service template that is resolvable 100% of the time, and the third one requires a service template that cannot always be resolved so needs to be guarded with conditions. Then youâve asked why a service template that does resolve 100% of the time isnât enough, but that template doesnât match the requirement you asked for when I gave the third example because it relies only on time, and takes no account of sun position.
I really donât know how I can help if the goal posts get moved every time I give you a solution
Sorry about that. I can see that I wrongly pasted another piece of code here, that I was playing with.
I will try to play around with the two you created in the first place. They seem to do what I need for now.
The main goal here is to use my Xiaomi button to do several things depending on the time.
If my daughter clicks the Xiaomi button once, the light should turn on a LED light, but only if the sun is down and before 22:00. If she clicks again it should turn off.
But, if she presses the button during 22 and 06 (perhaps before sunrise instead), then it should call another script that turns on some lighs towards the master bedroom for 10 minutes and then turn offâŚ
Basically what you need to do is work out exactly what the parameters are that need to be checked when the button is pressed, and then based on that formulate the correct combination of templates / scripts to make it happen.
The tricky bit is actually working out what the combinations of parameters are, after that the templates should be easy enough.
Look at every hour from 00:00 to 23:59 and think "if I press the button now, what should happen?
Light goes on?
Probably not
further checks?
Yup, first check is âis the light already on?â, then if yes switch the light off, if not go for some more further checks. Next check is the sun down etc etc.
If you can make it in to a flow chart, then it can be made to happen, but you need to get the flow chart right first, because as youâve seen above the slightest change to the flow chart makes massive changes to the automation
I tried to put down a notepad drawing and I hope it makes sense.
Here is what I came up with:
Xiaomi Click Button - Single Press
Single Click
|
|
Is the time between sunrise and sunset ------------------------> Yes - Do nothing
|
|
No
|
Is the time between sunset and 22? ------> Yes
| |
| |
| Is the light turned on? ----> Yes - Turn off light
| |
| |
| No
| |
| Turn off light
|
No
|
Is the time between 22 and sunrise ---------------------------> Yes - run script (Turn on path light and other stuff)
|
|
No
|
Do nothing (run dummy script perhaps)