Depends on what exactly are the conditions.
I understand it as : turn it on at 5.30 even if no motion detected and if motion is detected even during day. I would do 3 automations for that, they’d look like this :
alias : ‘morning light’ #start at 5:30
trigger : time
at: ‘05:30:00’
action: turn_on
alias: ‘on motion’ #if something moves out of the full on times
trigger: motion
condition: time after:‘08:00:00’ before ‘05:30:00’
action: turn on, delay 2mn, turn off
This is of course to adapt to the actual services (I don’t use zwave), but the important part in your question seemed to be the trigger logic ?
If you wanted to have only one automation with several triggers, always remember that list of trigger is possible, in that case it means an ‘OR’ between the events.
While a ‘condition’ list is an ‘AND’ (and you can create an OR, even OR and AND nested)
you realize tho that it will cause the light to turn off after 2 minutes even if the motion detector is still on (i.e. still detecting motion)? is that what you want?
I’m not sure what your feelings are on the configurator but I really dislike using it.
the way everything gets laid out is inconsistent and (therefore) confusing to try to parse out for us normal humans.
I’d much rather just type it in myself.
and another pro-tip …
when you post code and want it to display properly formatted, highlight the code snippet and then click the </> button at the top of the editor window. after that it should format it exactly as you have it formatted in your configuration file.
The way I lay it out is like the examples in the docs. It makes the most sense to me:
- id: '1521237256289'
alias: Auto_Mirror_On_Mouvement
trigger:
- platform: state
entity_id: binary_sensor.sensor_2
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: time
after: '05:30:00'
before: '08:00:00'
- condition: state
entity_id: binary_sensor.sensor_2
state: 'off'
action:
- service: switch.turn_on
entity_id: switch.switch_4
- delay: 00:02:00
- service: switch.turn_off
entity_id: switch.switch_4
the above should work.
notice you had your times switched around too.
I say “should” because I think I remember having a problem with a condition statement a recently where it didn’t like either an ‘or’ or an ‘and’ condition. I kept getting errors in the config check. if that happens let us know and there may be a way to work around it. But the docs say that an ‘and’ condition should work…so who knows
Indeed, it makes more sense…
However, it’s not working.
Testing configuration at /home/homeassistant/.homeassistant
ERROR:homeassistant.util.yaml:mapping values are not allowed here
in "/home/homeassistant/.homeassistant/automations.yaml", line 22, column 17
Failed config
General Errors:
- mapping values are not allowed here
in "/home/homeassistant/.homeassistant/automations.yaml", line 22, column 17
Successful config (partial)
The line 22 is this one:
condition:
condition: and
**conditions**:
- condition: time
I cannot understant that part. Could you explain why the “condition: and” is necessary?
Anither question is: What is this id? Is it radomly generated? If I write my own automation, can I write any ID?
The line you’ve put the stars round needs to come left 2 spaces so that the c for conditions is under the c of condition.
Then the two actual condition blocks all need moving back 2 spaces so their hyphens are under the n of conditions.
AND is saying both conditions need to be true for the automation to fire (as opposed to one OR the other)
ID is only used for the automation editor, so it can keep track of where in the file to edit. You don’t need to use it if you’re manually writing automations.
yeah, sorry about that. I got carried away with my indents.
Like mf_social said you don’t need the id: but I have just started putting it in there as a habit just in case I want to use the automation editor at some point in time. and you can put any unique name in there that you want. if you use the automation editor to create the automation then it randomly assigns one by default.
In fairness, IMO it would make more sense if it was supposed to be indented like that, seeing as how everything else does. Just another idiosyncrasy of the system
I understand lot better how automation works. Again thank you.
I have no errors, but the mirror won’t light up.
I thougt it could be because of the “before” “after” time switched, but no.
It probably is because the two conditions are not compatible.
I didn’t actually read the automation, but now I have, that one will never fire because the trigger is the sensor going on, but one of your conditions is the sensor being off. Obviously both can’t be true at the same time.
Yeah I was just looking over your initial post and the automation you posted above using the automation editor (and that I subsequently edited) won’t do what you initially wanted. it will only come on between 0530 and 0800 if it sees motion.
I have to step away for a little while but if i get the chance i’ll repost another automation for your use (unless you figure it out on your own by then ).
EDIT:
OK and what mf_social said above too. I didn’t read it either I just laid what you had written out differently.