Turn on lamp when TV is on

Could you chance

to this

      service: homeassistant.turn_on
      entity_id: light.lamp

and see if this works?

I am still banking on you having the correct entity_id of the lamp in here.

When your TV is off what does sensor.living_tv show as it’s state in the states-dev tool? Should be ‘off’. Now while watching that sensor, turn your TV on do you see its state change to ‘on’?

I really appreciate you help Dennis / Mike. It’s very annoying that it isn’t working because I can’t see a reason for it not to be. I changed it to “homeassistant.turn_on” and it made no difference. And just in case you’re dubious of the entity_id, here it is:

When the TV is off the sensor does show as “off” in the dev tool. When I turn the TV on the state changes to “on”. It doesn’t change automatically in the dev-tool. I have to hit enter again to refresh it but I take it that’s supposed to happen?

If your sensor is updating correctly then we can focus on the automation.

It appears correct to me, do you have any error messages?

Can you control the light.lamp from the service controller thing in the dashboard under devtools?

Hmm interesting. The state should change without a refresh.

Are you looking at this area of the states-dev tool?

Sorry Mike I thought you were referring to the value_template value on the template-devtool.
In the states-devtool the lamp never goes on. Even if I set it to ‘on’ on the state-devtool it doesn’t turn on. However if I switch it on via the dash (see image) then it does turn on!

Look in the section of the states dev tool that I posted for an entity called sensor.living_tv. With the TV turned off what does the state column show?

Even if I set it to ‘on’ on the state-devtool it doesn’t turn on.

Setting the state there will only change the value of the state. It won’t actually turn on/off the device.

EDIT: I meant sensor.living_tv, corrected myself above.

Could you chance the friendly name of your lamp to light.iworksomehow and also your automation to reflect this.

      service: homeassistant.turn_on
      entity_id: light.iworksomehow

To chance the friendly name place this in the customise: section

    light.lamp:
      friendly_name: iworksomehow

Restart HA and try the automation again.

Ah, under the state-devtool there is no “sensor.living_tv”. Not sure why.
In my config I have this:

sensor:
  - platform: yr
  - platform: template
    sensors:
      living_tv:
       value_template: "{%- if states.switch.living_room_tv.attributes['Current consumption'] | replace(' W', '') | float | float > 20 %}on{% else %}off{%- endif %}"

@dennisaion I attempted to rename the lamp but it didn’t work, I’m guessing because the sensor isn’t in the states-devtool

You analyzed your prop already.

Try. I think you are one space short on the value_temp line.

sensor:
  - platform: yr
  - platform: template
    sensors:
      living_tv:
        value_template: "{%- if states.switch.living_room_tv.attributes['Current consumption'] | replace(' W', '') | float | float > 20 %}on{% else %}off{%- endif %}"

Restart HA, hopefully your sensor will now show up.

Try this formatted version

sensor:
- platform: yr
- platform: template
  sensors:
    living_tv:
      value_template: "{%- if states.switch.living_room_tv.attributes['Current consumption'] | replace(' W', '') | float | float > 20 %}on{% else %}off{%- endif %}"

Woohoo it works! It’s not very responsive but it works! Thanks so much for all your help. I’ve learnt quite a bit through all this troubleshooting so much appreciated.

No problem. Enjoy.

ps: Don’t forget to try your original automation rule. This should work now and give better response.

1 Like

Glad you got it working. Welcome to the community and your new obsession. :slight_smile:

1 Like

On a bit of a tangent, I’ve just set up my led strip backlight to turn on and off with the TV. As it’s a smart TV, ha discovers it automatically as a media player and sees the on or off state as it joins and leaves the network, I’ve also set up a condition so it only happens if the sun is below the horizon. On top of this I’ve set another trigger that turns on the backlight at sunset but with the condition that the TV is on in case it’s already on.

Sad but I was quite chuffed as this was my first completely unblagged automation :slight_smile:

1 Like