LED brightness depending on Sensor

Hi
i have got a LED, a motion sensor und a brightness sensor.

The LED tunrs on when motion is detected.

I want the brightness of the LED to be dependend on the brightness sensor.
(255 - brightness sensor)

examples:

  • Motion detected, Brighness: 255, LED brightness: 0
  • Motion detected, Brighness 155, LED brighness 100

LED:

light:
  - platform: mqtt
    name: "dev_led"
    state_topic: "dev/1/dev_led/state/power"
    command_topic: "dev/1/dev_led/command/power"
    brightness_state_topic: "dev/1/dev_led/state/brightness"
    brightness_command_topic: "dev/1/dev_led/command/brightness"
    brightness_scale: 255
    qos: 0
    payload_on: "1"
    payload_off: "0"
    optimistic: false

Motion

binary_sensor:
  platform: mqtt
  state_topic: "dev/1/motion"
  name: "arbeitszimmer_motion"
  qos: 0
  payload_on: "on"
  payload_off: "off"

Brightness (Potentiometer for testing)

- platform: mqtt
    state_topic: "dev/1/pot"
    name: "pot"
    unit_of_measurement: ""

Automation

  - alias: "Hallway Motion"
    trigger:
      platform: state
      entity_id: binary_sensor.arbeitszimmer_motion
      to: 'on'
    action:
      service: homeassistant.turn_on
      entity_id:
        - light.dev_led
  - alias: "Hallway Timer"
    trigger:
      platform: state
      entity_id: binary_sensor.arbeitszimmer_motion
      to: "off"
      for:
        seconds: 10
    action:
      service: homeassistant.turn_off
      entity_id: light.dev_led

I want something like this:

 - alias: "Hallway Motion"
   trigger:
     platform: state
     entity_id: binary_sensor.arbeitszimmer_motion
     to: 'on'
   action:
     service: light.turn_on
     entity_id:
       - light.dev_led
     data:
       brightness: sensor.pot

Posting with correct formatting will allow people to better help you.

Please highlight your code, then use the pre-formatted text button in the editor as shown below:

 - alias: "Hallway Motion"
   trigger:
     platform: state
     entity_id: binary_sensor.arbeitszimmer_motion
     to: 'on'
   action:
     service: light.turn_on
     entity_id:
       - light.dev_led
     data_template:
       brightness: '{{ 255 - (states("sensor.pot") | int) }}'
1 Like

@taces2
can you post your yaml config and report how things are working. I am also looking for that kind of coding

This is my working automation.
I haven’t change the light or sensor component from the first post.
I added the automation “led_nach_sensor” so that the brightness changes when the state of the sensor changes

   automation:
      - alias: "Hallway Motion"
        trigger:
          platform: state
          entity_id: binary_sensor.arbeitszimmer_motion
          to: 'on'
        action:
          service: light.turn_on
          entity_id: light.dev_led
          data_template:
            brightness: '{{ 255 - (states("sensor.pot") | int) }}'
      - alias: "Hallway Timer"
        trigger:
          platform: state
          entity_id: binary_sensor.arbeitszimmer_motion
          to: "off"
          for:
            seconds: 10
        action:
          service: homeassistant.turn_off
          entity_id: light.dev_led
      - alias: "led_nach_sensor"
        trigger:
          platform: state
          entity_id: sensor.pot
        condition:
          condition: state
          entity_id: light.dev_led
          state: "on"
        action:
          service: light.turn_on
          entity_id: light.dev_led
          data_template:
            brightness: '{{ 255 - (states("sensor.pot") | int) }}'

I am going to add an input select
“auto” or “manuell”
so i can manually change the led if i don’t want the automation
for example when i start a scene like “movie”