Hi All, I’m running home assistant core, and have been having a bit of trouble with an automation to turn a light group on/off with a specified brightness. Basically, I have an automation that turns on a light group in my kitchen when motion is detected, and another that turns it off after a minute of no motion. The basic automation to turn on and off works just fine, the problem is when I try to add logic to turn the light on with a brightness_pct setting added in.
When I add this automation, the automation will no longer work properly, I’ve seen it trigger once after restarting home assistant, and now its not reacting at all to motion… I was hoping someone may be able to help me troubleshoot where I’m going wrong. I’m assuming there may be something wrong with my if/else block, here is the relevant block of code as it appears in my automations.yaml:
- id: '1565162664975'
alias: Kitchen Motion Lights On When Movement Detected
trigger:
- entity_id: binary_sensor.samjin_motion_fcf00601_ias_zone
platform: state
to: 'on'
- entity_id: binary_sensor.samjin_motion_e5ad0701_ias_zone
platform: state
to: 'on'
condition: []
action:
- data:
entity_id: light.kitchen_lights
brightness_pct: >
{% if now().hour > 22 %} 1
{% elif now().hour < 7 %} 1
{% else %} 100 {% endif %}
service: homeassistant.turn_on
- id: '1565163530303'
alias: Kitchen Lights Off After A Minute Of No Motion
trigger:
- entity_id: binary_sensor.samjin_motion_fcf00601_ias_zone
for: 00:00:30
platform: state
to: 'off'
- entity_id: binary_sensor.samjin_motion_e5ad0701_ias_zone
for: 00:00:30
platform: state
to: 'off'
condition:
- condition: state
entity_id: binary_sensor.samjin_motion_fcf00601_ias_zone
for: 00:00:30
state: 'off'
- condition: state
entity_id: binary_sensor.samjin_motion_e5ad0701_ias_zone
for: 00:00:30
state: 'off'
action:
- data:
entity_id: light.kitchen_lights
service: homeassistant.turn_off
Note the brighness_pct code under the “Kitchen Motion Lights On When Movement Detected” alias.
There are a few other things I am confused about as well that maybe someone can clear up:
I am using the service: homeassistant.turn_on /off because I think that a light group cannot be triggered by a service: light.turn_on/off call, is this true?
I am using data: under the action: section because I get an error when I try to use “data_template” (which I saw being used in a bunch of examples online)… I get this error in the UI automation editor when I put in data_template:
UI editor is not supported for this config:
Key "data_template" is not expected or not supported by the visual editor. You can still edit your config in YAML.
Am I actually able to use data_template, and I should just ignore the error? Regardless, the automation still doesn’t work if I use data_template, so I’m still dead in the water.
The entities in this yaml are not groups. If it was a group, the entity id would have started with group and not light. The light.kitchen_lights is a light entity and you should use light.turn_on and light.turn_off
I thought that this was how light groups were implemented, but it is possible I am completely off base, does this look like a proper implementation to you?
I called the light.kitchen_lights service from the services tab of the developer console, and the lights turn on successfully. I tried adding the brightness_pct section as part of the Service Data, and get an error:
Failed to call service light/turn_on. expected float for dictionary value @ data[‘brightness_pct’]
looks like its having trouble with my if/else statement.
Unfortunately, it is still not working, although I did notice some behavior I had not noticed before. After one minute, and the light.turn_off service is called, the lights briefly flare on before turning off… Not sure why that is happening.
My proposal is to resolve that scripting part into a choose sequence. You can then use a time-based condition after: 22:00:00 and before: 07:00:00. Using full brightness would be the default then.
Turns out we were looking down the wrong path for the solution, the issue was actually with the bulbs themselves. I am using Sylvania smart+ (LEDVANCE) 73739 color BR30 bulbs from 2017, which apparently had a bug related to brightness settings.
I figured out this was the case from another forum post from July 2020 that @tom_l was actually a part of:
I am using the ZHA integration to control my bulbs, so I then looked into updating the firmware on my bulbs, and found that it was possible from this reddit post (also mentioned in the ZHA integration page, but the reddit post describes how to force an update):
I did end up utilizing @m0wlheld’s recommendation to utilize a choose sequence, so in case anyone is curious how that turned out, here is my final implementation; the choose sequence has a nice implementation in the automations UI:
- id: '1565162664975'
alias: Kitchen Motion Lights On When Movement Detected
trigger:
- entity_id: binary_sensor.samjin_motion_fcf00601_ias_zone
platform: state
to: 'on'
- entity_id: binary_sensor.samjin_motion_e5ad0701_ias_zone
platform: state
to: 'on'
condition: []
action:
- choose:
- conditions:
- condition: time
after: "22:00:00"
before: "07:00:00"
sequence:
- service: light.turn_on
entity_id: light.kitchen_lights
data:
brightness_pct: 1
default:
- service: light.turn_on
entity_id: light.kitchen_lights
data:
brightness_pct: 100
I seriously probably attempted to get past this issue at least 10 times the last 1.5 years, and just ended up giving up every attempt till now. Lesson learned, always check for firmware updates if things that should be behaving are not. Thanks everyone for the help!