this post was submitted on 05 Nov 2024
10 points (100.0% liked)

homeassistant

11998 readers
106 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

founded 1 year ago
MODERATORS
 

Trying to run an automation to match one light's state (on/off/dim) to another's. Have this currently:

alias: Sync cabinet lights with sink light
if:
  - condition: device
    type: is_on
    device_id: [something]5710
    entity_id: [something]a438
    domain: light
then:
  - type: turn_on
    device_id: [something]b447
    entity_id: [something]470f
    domain: light
    brightness_pct: 100
else:
  - type: turn_off
    device_id: [something]b447
    entity_id: [something]470f
    domain: light

That works fine to turn the lights on or off, and I have triggers in the automation for that and changes in brightness. But using a non-static number for brightness_pct (yes, I know I'll probably have to math the 0-100 scale instead of 0-255) is giving me trouble. When I try something like this:

alias: Sync cabinet lights with sink light
if:
  - condition: device
    type: is_on
    device_id: [something]5710
    entity_id: [something]a438
    domain: light
then:
  - type: turn_on
    device_id: [something]b447
    entity_id: [something]470f
    domain: light
    brightness_pct: {{state_attr("light.kitchen_sink_ceiling", "brightness")}}
else:
  - type: turn_off
    device_id: [something]b447
    entity_id: [something]470f
    domain: light

I have also tried {{states.light.kitchen_sink_ceiling.attributes.brightness}} instead. Both seem to have the correct value when I play around in the developer tools. But when I put it in the automation, I get an error that a float value was expected. I see some similar issues online, but it always seems to be in a different context and people fix it by changing some value I never had.

you are viewing a single comment's thread
view the rest of the comments
[–] InEnduringGrowStrong@sh.itjust.works 1 points 2 days ago* (last edited 2 days ago)

Oh.. I think you also need double quotes around template brackets when used as the value in a service call..? Which conflicts with the quotes around the entity and attribute so just use single quotes there.

brightness_pct: "{{state_attr('light.kitchen_sink_ceiling', 'brightness')}}"

Just whipped up a partial example with my living room lights. It is missing a trigger and an else butI focused on theactionyou had trouble with.
Using brightness instead of brightness_pct seemed simpler. (Or at least if both can usethe same attribute...)

alias: Example
description: ""
trigger: []
condition:
  - condition: state
    entity_id: light.living_room_floor_lamp_1
    state: "on"
action:
  - action: light.turn_on
    metadata: {}
    data_template:
      brightness: "{{state_attr('light.living_room_floor_lamp_1', 'brightness')}}"
    target:
      entity_id: light.living_room_floor_lamp_2
mode: single