Automation to turn on light and set brightness

I created an automation to turn a group of lights based the state of sensor.0x00178801080a6c9f_action which will turn the lights on however it always turns it on to to max brightness. The sensor has an attribute named brightness but I can figure out how to integrate that into my automation. Looking for some suggestions. Here is the sensor and current automation.

Sensor data:

counter: 1
linkquality: 63
last_seen: 1572634894977
brightness: 31
battery: 100
action: 
friendly_name: HallwaySwitch_action
icon: mdi:gesture-double-tap

Automation

- id: '1572632573806'
  alias: Hallway Switch On
  description: ''
  trigger:
  - entity_id: sensor.0x00178801080a6c9f_action
    platform: state
    to: on-press
  condition: []
  action:
  - data:
      entity_id: group.basement_hallway
    service: light.turn_on
- id: '1572632573806'
  alias: Hallway Switch On
  description: ''
  trigger:
  - entity_id: sensor.0x00178801080a6c9f_action
    platform: state
    to: on-press
  condition: []
  action:
  - data_template:
      entity_id: group.basement_hallway
      brightness: "{{ trigger.to_state.attributes.brightness }}"
    service: light.turn_on
2 Likes

Thanks for the response however adding

brightness: "{{ trigger.to_state.attributes.brightness }}

to the automation causes it not to work.

The home assistant log threw this error:

Error while executing automation automation.hallway_switch_on. Invalid data for call_service at pos 1: expected int for dictionary value @ data['brightness']

Not entirely sure what this means but It give me something to search off of.

Did you also change data to data_template?

I missed that part. Thanks! It worked as expected. I’ve been working on this far longer than I care to admit. Now I just need to figure out how to make adjusting the brightness work once they are on. Thanks a bunch seems like I need to learn about templates a bit.

BTW, what is the range of values of the brightness attribute of sensor.0x00178801080a6c9f_action? Is it 0 - 255, or 0 - 100? If the latter, then you’ll want to change brightness to brightness_pct in the service call.

It’s 0-255.

1 Like