Great example! Thanks! Will replicate that one.
Do you have any code to show how you use the sleep_state
variable? I would like the areas to stop turning on the lights after 23:00 and not before 05:00. And some areas at different times than that. How do you accompish that?
Right now the lights goes on in the bedroom when my wife wakes up in the middle of the night. It should be only the night lights as you intended. Seems like I am missing a binary_sensor.night_mode
in Magic Areas?
-EDIT: Okay, I figured out that I needed to create that binary_sesnors.night_mode myself in configuration.yaml, but this code does not work:
binary_sensor:
- platform: template
sensors:
night_mode:
friendly_name: "Night mode"
value_template: >- ## Time after 23:30 and before the next dawn.
{{ (states('sensor.time') > "23:30")
or as_timestamp(strptime(state_attr('sun.sun', 'next_dawn'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom('%H:%M') < now().strftime("%H:%M") }}
Is this really supposed to be done manually by each user of Magic Areas or should your (awesome) component do it automatically for us? It wasnât easy to figure out this one so I think many users would love to have Magic Areas do this.
I guess the same goes for the disable_entity
binary sensor?
Well, that previous code did not work so I simplified and used this instead:
binary_sensor:
- platform: tod
name: Night Mode
after: '00:00'
before: '08:00'
That one work correctly.
I guess your bathroom lights are not dimmable?
Your template was almost right! You have the 2nd test backwards. It says or Dawn < Now()
which can only be true if the current time is after Dawn. Either change <
to >
or reverse the operators.
{{ (states('sensor.time') > "23:30")
or states('sensor.time') < as_timestamp(strptime(state_attr('sun.sun', 'next_dawn'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom('%H:%M') }}
I have templated sensors for the sun.sun attributes:
# Sun
next_midnight:
friendly_name: 'Next Midnight'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_dusk) | timestamp_custom('%H:%M')}}
icon_template: mdi:weather-sunset-up
next_dawn:
friendly_name: 'Next Dawn'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_dawn) | timestamp_custom('%H:%M')}}
icon_template: mdi:weather-sunset-up
next_sunrise:
friendly_name: 'Next Sunrise'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom('%H:%M') }}
icon_template: mdi:weather-sunset-up
next_noon:
friendly_name: 'Next Noon'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_dusk) | timestamp_custom('%H:%M')}}
icon_template: mdi:weather-sunset-up
next_sunset:
friendly_name: 'Next Sunset'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom('%H:%M') }}
icon_template: mdi:weather-sunset-down
next_dusk:
friendly_name: 'Next Dusk'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_dusk) | timestamp_custom('%H:%M')}}
icon_template: mdi:weather-sunset-up
so then your sensor.night_mode could be:
value_template: >- ## Time after 23:30 **or** before dawn.
{{ (states('sensor.time') > "23:30")
or states('sensor.time') < states('sensor.next_dawn') }}
Better yetâŚcreate an input_datetime helper and use that instead of â23:30â for flexibility.
If your input helper could be > midnight (i.e. 00:30) youâll have to add if-then-else logicâŚ
{% if states('input_datetime.helper') < states('sensor.next_dawn') %}
{{ states('sensor.time') > states('input_datetime.helper')
and states('sensor.time') < states('sensor.next_dawn') }}
{% else %}
{{ states('sensor.time') > states('input_datetime.helper')
or states('sensor.time') < states('sensor.next_dawn') }}
{% endif %}
Nice! Iâll look closer into this. Thanks, Daniel!
Youâre looking for the disable_state
variable. Sleep state will only turn a different set of lights on (good for night lights).
I used to use this same type of sensor for sleep_state
. Nowadays I use GitHub - basnijholt/adaptive-lighting: Adaptive Lighting custom component for Home Assistant which gives me a sleep switch which i use as sleep_state
. I have an automation that flips the sleep switch from adaptive lighting at given situations (bed is clear, time of day etc).
For the disable_state
I use the exterior light levels. But itâs the same drill.
Thanks for the clarifications!
What do you mean with âexterior light levelsâ? How do you use outdoor lights to control the disable_state binary_sensor?
I have a sensor outside (custom made) that report light levels (there are z-wave ones that can report that information as well). Then I have a template binary sensor called âexterior_lightâ with a template that if the light level is < a given value it turns off. I use this sensor as my disable_entity
.
binary_sensor:
- platform: template
sensors:
light_exterior:
friendly_name: "Light (Exterior)"
device_class: light
value_template: "{{ states('sensor.luminosity_weather_station')|int > 50 }}"
unique_id: binary_sensor_light_exterior
I just realized Iâve been saying disable_state
but the parameter is actually disable_enitity
.
Does Magic Area care about the timeout value on Motion Sensors?
Should I use the timeout value in Magic Area or on the motion sensor?
Theyâre related. The timeout of MagicAreas will start counting after the motion sensor goes to off
state which depends on their timeout. If you have multiple motion sensors in the same area, MagicAreas will start counting after the last one goes to off
.
Okay, thanks. Good to know.
Maybe add it to your Magic Areas info?
Iâm wondering if Magic Areas has a bug regarding the motion sensors. When I enter a room and the âAeotec MultiSensor 6â detects presence, the lights turn on as they should.
However when I observe the âActive sensorsâ for the current Area, the motion sensor shows up there, but just for 3-4 seconds, and then it is gone. 10 minutes later (Clear timeout), all lights goes off even though the motion sensor is set to 1800 seconds (30 minutes).
Shouldnât it be 30 minutes motion sensor + 10 minutes Area before timeout actually occurs?
Thatâs weird, can you check the sensor state in Home Assistant if it goes to off
after 3-4 seconds as well? MagicAreas should follow that.If the sensor is on
and the area is cleared, then itâs a bug
I have testet more closely and the Aeotec MultiSensor 6 have two sensors regarding the motion sensor.
This binary sensor senses the movement and says briefly âDetectedâ and goes back to âClearâ after a few seconds:
binary_sensor.multisensor_jupiter_home_security_motion_detected
The next binary sensor goes to On when detection occurs and stay there until it times out based on the OpenZWave node config value for the sensor (default is 240 seconds/4 minutes):
binary_sensor.multisensor_jupiter_sensor
Magic Areas uses the first binary sensor by default, which in this case is the wrong one. I tried to add the second one in configuration.yaml as âinclude_entities:â, but that did not work.
Is it possible to fix this for your 2.0 release or is it something I can do to make it work?
Additional info: The Developer Tools says the first binary sensor is device_class: motion.
The second one have no device class. So if I do like this in configuration.yaml, it should work in Magic Areas 2.0 I presume?:
homeassistant:
customize_glob:
binary_sensor.multisensor_jupiter_sensor:
device_class: motion
I have installed Magic Areas succesfully! I have made an own Area in the configuration file named Office.
but the area is not showing up in the entities. Only the self made areaâs
Release 2.0.0 is out! This should fix your issues with customize!
There was a bug when you had only one area defined. Update to 2.0.0 (read the release notes!) and this shall be fixed.
READ THE RELEASE NOTES!
YAML configuration SHOULD work but I havenât tested tbh. With the addition of config flow, now you can manage all the config options from the Integrations UI and the area will reload automatically after changing options, no more restarts! (Well, some corner cases)
Let me know your comments after testing the new release!
Looking good so far. I guess it has been a massive job preparing for 2.0. Itâs really nice to just do the changes directly instead of a planned restart. And all the custom device classes showed up as well.
Media Players added as presence sensors does not seem to work in 2.0 as it did in the previous 1.x version. It never shows up as active sensor. Do you want me to report it on Github or just here?
I also having problem getting some zones to turn on lights, but I need to test more.
Please open a ticket on github, will try to fix that today!
Fixed on 2.0.1, give it a test!