Light.turn_on/off when computer (ping) goes on/off

I’m wanted to create a automation that turns the computer light on when the computer is running. Better for the eyes :wink:

I added a ping to check if my computer has been turned on. This sensors is working:

binary_sensor:
  - platform: ping
    host: 192.168.1.100
    scan_interval: 15
    name: Computer

Now i made a automation:

- id: '1597745411283'
  alias: Woonkamer computerlamp uit
  description: ''
  trigger:
  - device_id: deadfe91fb3b4032a33de1ebc64a9020
    domain: switch
    entity_id: switch.computer
    platform: device
    type: turned_off
  condition: []
  action:
  - data:
      transition: 15
    entity_id: light.lumi_lumi_light_aqcn02_09892a04_level_light_color_on_off
    service: light.turn_off
  mode: restart

But this is not working and the light is not going on or off.

What am i doing wrong?

Those device triggers are horrendously messy, as are the rest of the ui generated automations…

- id: '1597745411283'
  alias: Woonkamer computerlamp uit
  trigger:
    platform: state 
    entity_id: switch.computer
  action:
    service_template: "light.turn_{{ trigger.to_state.state }}" 
    data:
      entity_id: light.lumi_lumi_light_aqcn02_09892a04_level_light_color_on_off
      transition: 15

(this assumes that switch.computer is a thing, because the code you pasted was for a binary sensor)

Yup, i create my automatons mostly off the UI. But i’m slowly learning the YAML way, and you also helped me a little bit with the learning :+1:

And thanks. This does the trick. Although i had indeed a wrong device selected. but changed that to the binary sensor

- id: '1597745411283'
  alias: Woonkamer computerlamp aan/uit
  trigger:
  - entity_id: binary_sensor.computerping
    platform: state
  action:
  - data:
      entity_id: light.lumi_lumi_light_aqcn02_09892a04_level_light_color_on_off
      transition: 15
    service_template: light.turn_{{ trigger.to_state.state }}
  mode: single
1 Like

Another question: I want to set the brightness from the light to about 70% when going on. But when i add:

brightness_pct: 70

it is not turning off anymore.