Refresh the status after HA reboot

Hi all,
I’d like to refresh the status of my devices when HA reboots (for example when I reboot the raspberry for other reasons).
Happens this:
when I reboot HA and the TV is turned on, the input boolean remains turned off…

input_boolean:
  tv:
    name: Accensione tv
    initial: off
    icon: mdi:television

script:
  sequenza_on_tv:
    alias: "tv"
    sequence:
      - service: media_player.turn_on
        entity_id: media_player.oled_lg
      - service: media_player.turn_on
        entity_id: media_player.skyq_living_room

  sequenza_off_tv:
    alias: "tv"
    sequence:
      - service: media_player.turn_off
        entity_id: media_player.oled_lg
      - service: media_player.turn_off
        entity_id: media_player.skyq_living_room

automation tv:
- alias: "rileva TV ON"
  trigger:
    platform: state
    entity_id: media_player.oled_lg
    to: 'on'
  condition:
    condition: state
    entity_id: input_boolean.tv
    state: 'off'
  action:
    service: input_boolean.turn_on
    entity_id: input_boolean.tv

- alias: "rileva TV OFF"
  trigger:
    platform: state
    entity_id: media_player.oled_lg
    to: 'off'
  condition:
    condition: state
    entity_id: input_boolean.tv
    state: 'on'
  action:
    service: input_boolean.turn_off
    entity_id: input_boolean.tv

- alias: "tv"
  trigger:
    platform: state
    entity_id: input_boolean.tv
  condition: []
  action:
    service: script.turn_on
    data_template:
      entity_id: >
        {% if trigger.to_state.state == 'on' %}
        script.sequenza_on_tv
        {% elif trigger.to_state.state == 'off' %}
        script.sequenza_off_tv
        {% endif %}

If HA refreshes the status of media_player.oled_lg, I think this won’t happens…

Remove this from your input_booleqn config:

initial: off

This setting tells HA that the input boolean should always be off when the system starts. If you remove this setting it will have the state it had before the reboot.

Remove initial: off

input_boolean:
  tv:
    name: Accensione tv
    icon: mdi:television

Oeps! @Burningstone just replied before me :wink:

many thanks, but if the status of the tv changes when HA reboots the problem remains, am I wrong?

Of course. How is HA supposed to know the status during a reboot?

Chances are relatively low that this happens during a reboot (for me a reboot takes less than 30 seconds). You could add an automation that checks the media_player after HA started and sets the input boolean, but that’s overkill in my opinion.
Just don’t reboot your Pi when someone is about to start/stop watching TV xD