I’m pretty new out here and i have some questions…
I have a daughter who, when she supposed to be in bed sneaks around, now i have put a door sensor on her door, horrible me .
I want to automate it with te following:
when she goes to bed at 19:00/19:30 and she leaves her room, i want to turn a light in our livingroom in a colour and if we put her in bed again and close the door, i want to turn the light back to it original colour.
this what i have, at this point
- alias: deur open
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.0x00158d00024605ed_contact
from: 'off'
to: 'on'
action:
- service: light.turn_on
entity_id: light.hoeklampje
data:
brightness: 150
rgb_color: [255, 0, 0]
- alias: deur dicht
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.0x00158d00024605ed_contact
from: 'on'
to: 'off'
action:
- service: light.turn_on
entity_id: light.hoeklampje
data:
brightness: 150
rgb_color: [247, 245, 163]
it’s working, but…
these are 2 different automations, is there a way to put in in 1?
the colour in the 2nd automation is not the original colour, where it was, is it possible to do so?
i do not know where i have to put a “timer” in, so the automation is active from 19:00 until 24:00/23:59
It can probably be combined into one automation, but it’s probably not worth the effort. It would become much more complicated for little pay pack. If it were me, I’d leave it as two automations like you have it (although I tend not to use the from: option with binary_sensor’s.)
To save and restore the light’s state, you could use a python_script I wrote for just this purpose. It is documented here, including an example of how you might use it.
Regarding limiting the time period in which these automations will run, you do that by adding a condition to your automations. E.g.:
condition:
condition: time
after: 19:00:00
before: 24:00:00
in my config folder i created a python_scripts folder and there i dropped your light_store.py file and saved it as a python source file.
then i copied the automations wich you suggested, it was a valid config, but no luck.
when i opened and closed the door (didn’t wake my daughter), there was also no change in my entity card.
Did you add python_script: to your configuration? Does the account that is running HA have permission to the folder and script? Do you see python_script.light_store listed in the available services on the Services page? Did you restart HA, or at least run the python_script.reload service?
Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘after’]. Got None
extra keys not allowed @ data[‘condition’][0][‘before’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None
required key not provided @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 261). Please check the docs at https://home-assistant.io/components/automation/
- alias: deur open
initial_state: true
trigger:
platform: state
entity_id: binary_sensor.0x00158d0002460515_contact
to: 'on'
condition:
condition: time
after: '19:00:00'
before: '24:00:00'
action:
- service: python_script.light_store
data:
store_name: deur
entity_id: light.hoeklampje
- service: light.turn_on
entity_id: light.hoeklampje
data:
brightness: 150
rgb_color: [255, 0, 0]
i get the following message:
Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘after’]. Got None
extra keys not allowed @ data[‘condition’][0][‘before’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None
required key not provided @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 261). Please check the docs at https://home-assistant.io/components/automation/
I don’t think that’s necessary, but of course, it doesn’t hurt to have them.
EDIT: Ok, I might be wrong here. I’m pretty sure times for at: in a time trigger don’t need to be quoted, but it does appear that times in a time condition do. Again, doesn’t hurt to quote times in both cases.
Hmm, can’t explain that. Are you sure the clock is set correctly on the system running HA, and the time zone setting in the environment (e.g., OS) and HA agree and are set correctly?