How to get state's value?

I created a button named “Watch TV”. It works fine, but in input_boolean where ‘initial’ is ‘off’ instead I would like to get an actual state of media_player.lg_webos_tv_remote. In other words if TV is turned on I need to return value for input_boolean as ‘on’ if TV is off value needs to be displayed as’off’. Can’t figure out how to, maybe someone could enlighten me?

input_boolean:
  watchtv:
    name: Watch TV
    initial: off --> I need to get an actual state value here of media_player.lg_webos_tv_remote
    icon: mdi:television

  - alias: Turn TV on
    trigger:
      platform: state
      entity_id: input_boolean.watchtv
      state: 'on'
    action:
      service: homeassistant.turn_on
      entity_id: media_player.lg_webos_tv_remote

  - alias: Turn TV off
    trigger:
      platform: state
      entity_id: input_boolean.watchtv
      state: 'off'
    action:
      service: homeassistant.turn_off
      entity_id: media_player.lg_webos_tv_remote

First off this is really weird. You have two input_boolean which are to turn something on/off. You should only need one of those. For your problem you could just configure a automation which triggers on state changes of you media_player component.

Cheers

1 Like

Thanks, but I dont understand why it is weird. What I want to accomplish is to have a power button which on connect turns on 3 devices (receiver, tv and chromecast). Same on opposite when you press button to disconnect. All would work but I need to have a correct status of button when HA starts.

Another way I was thinking where this scenario would be useful is look there: https://home-assistant.io/components/input_slider/
Line initial:30 If we could get a correct brightness status of the light we could present slider on correct input versus being it always on 30 when light could be shining at 60…

1 Like

Maybe you want to have a look at the command_line switch which has a status command to read the correct current state?