Enable binary sensor that uses cURL only when TV is on

Hi all,

I currently have a binary sensor that looks something like this.

Due to it trying to get a response even when the TV is off and spamming the log, I’m looking for a way to poll the TV only when it’s on.

I realise I can filter it out from the log but would prefer a more complete solution.

I was messing around with templates such as -

         {% if is_state('switch.switch_tv_on', 'on') %}  ********If TV is on********
          '{{ value_json.power }}'   ********execute curl and extract value********
         {% else %} 
          off    ********otherwise Ambilight is off********
         {% endif %} 

I realise the above isn’t correct but added the comments to indicate how it might work.

Thanks :slight_smile:

I think you need an automation triggered by when the tv is turned off and on.

Thanks! Totally blanked about using automation.

Current automations look like this.

- id: '1527574736600'
  alias: TV on - Ambilight sensor on
  trigger:
  - entity_id: switch.switch_tv_on
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - alias: ''
    data:
      entity_id: sensor.ambilight
    service: homeassistant.turn_on
- id: '1527574736601'
  alias: TV off - Ambilight sensor off
  trigger:
  - entity_id: switch.switch_tv_on
    from: 'on'
    platform: state
    to: 'off'
  - event: start
    platform: homeassistant
  condition: []
  action:
  - alias: ''
    data:
      entity_id: sensor.ambilight
    service: homeassistant.turn_off

Problem is it doesn’t appear to turn off the sensor at all. Nothing in log until I manually trigger it, then I get this warning:

Unable to find service sensor/turn_off