LG-Smart TV (turn on/of lights on sun) switch between decoder/smartbox/netflix/amazon-prime with all devices own power source

blueprint:
name: LG webOS – Streaming/Octagon scene controller
description: >
Combineert 5 automations: TV-aan scene op basis van bron, streaming verlaten → Octagon,
Sunset/Sunrise lamp-logica, JBL/Zitbank aanhouden zolang TV aan staat, en geforceerd
naar Octagon-bron met retry. Instelbaar via inputs (TV entity, bronnen, switches).
domain: automation
source_url: https://github.com/yourname/ha-blueprints/lg_webos_streaming_octagon

input:
tv:
name: LG TV (media_player)
selector:
entity:
domain: media_player

# Bronnen / namen zoals ze in de TV 'source_list' voorkomen
streaming_sources:
  name: Streaming bronnen (exacte 'source' namen)
  description: Exact zoals zichtbaar bij tv.source (bijv. Netflix, Prime Video).
  default:
    - Netflix
    - Prime Video
    - Amazon Prime Video
    - Amazon Prime
  selector:
    select:
      multiple: true
      custom_value: true
      options:
        - Netflix
        - Prime Video
        - Amazon Prime Video
        - Amazon Prime

octagon_source:
  name: Octagon bron (exacte 'source' naam)
  description: Bijvoorbeeld 'sf8008' of 'HDMI 1' (zoals in de source_list van de TV).
  default: sf8008
  selector:
    text: {}

f1_source:
  name: F1/Smartbox bron (optioneel, bv. 'HDMI 3')
  description: Wordt gebruikt om terug te schakelen naar Octagon als je F1 verlaat.
  default: HDMI 3
  selector:
    text: {}

# Apparaten/switches
sw_octagon:
  name: Octagon (SF8008) switch
  selector:
    entity:
      domain: switch
sw_f1:
  name: F1/Smartbox switch
  selector:
    entity:
      domain: switch
sw_jbl:
  name: JBL switch
  selector:
    entity:
      domain: switch
sw_sofa:
  name: Zitbank switch
  selector:
    entity:
      domain: switch
sw_kast:
  name: Kastlampen switch
  selector:
    entity:
      domain: switch
sw_kast_low:
  name: Lage kastlamp switch
  selector:
    entity:
      domain: switch

# Gedrag/robuustheid
delay_source_fill_seconds:
  name: Wacht (sec) na TV aan voordat bron wordt gelezen
  default: 5
  selector:
    number:
      min: 0
      max: 20
      unit_of_measurement: s
      mode: slider

keep_on_ping_minutes:
  name: Interval (min) om JBL/Zitbank aan te houden zolang TV aan is
  default: 10
  selector:
    number:
      min: 1
      max: 60
      unit_of_measurement: min
      mode: slider

force_source_retry_count:
  name: Aantal retries om naar Octagon-bron te schakelen
  default: 3
  selector:
    number:
      min: 1
      max: 5
      mode: slider

force_source_retry_delay:
  name: Wacht (sec) tussen retries
  default: 2
  selector:
    number:
      min: 1
      max: 10
      unit_of_measurement: s
      mode: slider

mode: restart

-----------------------------------------------------------

Triggers (de blueprint bundelt alle scenario’s)

-----------------------------------------------------------

trigger:

A) TV gaat aan (scene bepalen op basis van bron)

  • id: tv_on
    platform: state
    entity_id: !input tv
    to: ‘on’

B) Bronwijziging (om streaming verlaten op te vangen)

  • id: source_changed
    platform: state
    entity_id: !input tv
    attribute: source

C) Octagon switch aangezet → forceer bron

  • id: octagon_on
    platform: state
    entity_id: !input sw_octagon
    to: ‘on’

D) TV uit

  • id: tv_off
    platform: state
    entity_id: !input tv
    to: ‘off’

E) Sunrise/Sunset events

  • id: sunrise
    platform: sun
    event: sunrise
  • id: sunset
    platform: sun
    event: sunset

F) Keep-alive: JBL/Zitbank aanhouden zolang TV aan

  • id: keep_on_tick
    platform: time_pattern
    minutes: “/{{ iif((!input keep_on_ping_minutes) == 0, 10, (!input keep_on_ping_minutes)) }}”

-----------------------------------------------------------

Variabelen

-----------------------------------------------------------

variables:
tv: !input tv
streaming_sources: !input streaming_sources
octagon_source: !input octagon_source
f1_source: !input f1_source

-----------------------------------------------------------

Acties

-----------------------------------------------------------

action:

  • choose:

    ========== CASE 1: TV gaat aan ==========

    • conditions:

      • condition: template
        value_template: “{{ trigger.id == ‘tv_on’ }}”
        sequence:

      Wachten tot bron gevuld

      • delay:
        seconds: !input delay_source_fill_seconds

      Altijd JBL + Zitbank aan

      • service: switch.turn_on
        target:
        entity_id:
        - !input sw_sofa
        - !input sw_jbl

      F1 altijd uit

      • service: switch.turn_off
        target:
        entity_id: !input sw_f1

      Octagon uit als bron streaming is, anders aan

      • choose:
        • conditions:
          • condition: template
            value_template: >
            {{ state_attr(tv, ‘source’) in streaming_sources }}
            sequence:
          • service: switch.turn_off
            target:
            entity_id: !input sw_octagon
            default:
        • service: switch.turn_on
          target:
          entity_id: !input sw_octagon

      Lampen alleen na zonsondergang

      • choose:
        • conditions:
          • condition: sun
            after: sunset
            sequence:
          • service: switch.turn_on
            target:
            entity_id:
            - !input sw_kast
            - !input sw_kast_low

    ========== CASE 2: Streaming/F1 verlaten ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘source_changed’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’

      we kwamen VAN streaming óf F1

      • condition: template
        value_template: >
        {{ trigger is not none and trigger.from_state is not none and
        (trigger.from_state.state in streaming_sources or
        trigger.from_state.state == f1_source) }}

      we ZIJN nu NIET in streaming en NIET al op octagon_source

      • condition: template
        value_template: >
        {{ trigger is not none and trigger.to_state is not none and
        (trigger.to_state.state not in streaming_sources) and
        (trigger.to_state.state != octagon_source) }}
        sequence:

      Octagon aan, F1 uit

      • service: switch.turn_on
        target:
        entity_id: !input sw_octagon
      • service: switch.turn_off
        target:
        entity_id: !input sw_f1

      Lampen na zonsondergang

      • choose:
        • conditions:
          • condition: sun
            after: sunset
            sequence:
          • service: switch.turn_on
            target:
            entity_id:
            - !input sw_kast
            - !input sw_kast_low

    ========== CASE 3: Octagon switch gaat aan → forceer bron met retry ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘octagon_on’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’
        sequence:
      • delay:
        seconds: !input force_source_retry_delay
      • repeat:
        count: !input force_source_retry_count
        sequence:
        - service: media_player.select_source
        target:
        entity_id: !input tv
        data:
        source: !input octagon_source
        - delay:
        seconds: !input force_source_retry_delay
        - choose:
        - conditions:
        - condition: template
        value_template: >
        {{ state_attr(tv, ‘source’) == octagon_source }}
        sequence:
        - stop: “Octagon-bron geselecteerd”

    ========== CASE 4: TV uit of sunrise ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id in [‘tv_off’, ‘sunrise’] }}”
        sequence:
      • choose:

        TV uit → alles uit

        • conditions:
          • condition: template
            value_template: “{{ trigger.id == ‘tv_off’ }}”
            sequence:
          • service: switch.turn_off
            target:
            entity_id:
            - !input sw_sofa
            - !input sw_jbl
            - !input sw_kast
            - !input sw_kast_low
            - !input sw_octagon

        Sunrise → alleen lampen uit

        • conditions:
          • condition: template
            value_template: “{{ trigger.id == ‘sunrise’ }}”
            sequence:
          • service: switch.turn_off
            target:
            entity_id:
            - !input sw_kast
            - !input sw_kast_low

    ========== CASE 5: Sunset terwijl TV aan → lampen aan ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘sunset’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’
        sequence:
      • service: switch.turn_on
        target:
        entity_id:
        - !input sw_kast
        - !input sw_kast_low

    ========== CASE 6: Keep-alive (zolang TV aan is: JBL/Zitbank aan) ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘keep_on_tick’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’
        sequence:
      • service: switch.turn_on
        target:
        entity_id:
        - !input sw_sofa
        - !input sw_jbl

    default:

blueprint:
name: LG webOS – Streaming/Octagon scene controller
description: >
Combineert 5 automations: TV-aan scene op basis van bron, streaming verlaten → Octagon,
Sunset/Sunrise lamp-logica, JBL/Zitbank aanhouden zolang TV aan staat, en geforceerd
naar Octagon-bron met retry. Instelbaar via inputs (TV entity, bronnen, switches).
domain: automation
source_url: https://github.com/yourname/ha-blueprints/lg_webos_streaming_octagon

input:
tv:
name: LG TV (media_player)
selector:
entity:
domain: media_player

# Bronnen / namen zoals ze in de TV 'source_list' voorkomen
streaming_sources:
  name: Streaming bronnen (exacte 'source' namen)
  description: Exact zoals zichtbaar bij tv.source (bijv. Netflix, Prime Video).
  default:
    - Netflix
    - Prime Video
    - Amazon Prime Video
    - Amazon Prime
  selector:
    select:
      multiple: true
      custom_value: true
      options:
        - Netflix
        - Prime Video
        - Amazon Prime Video
        - Amazon Prime

octagon_source:
  name: Octagon bron (exacte 'source' naam)
  description: Bijvoorbeeld 'sf8008' of 'HDMI 1' (zoals in de source_list van de TV).
  default: sf8008
  selector:
    text: {}

f1_source:
  name: F1/Smartbox bron (optioneel, bv. 'HDMI 3')
  description: Wordt gebruikt om terug te schakelen naar Octagon als je F1 verlaat.
  default: HDMI 3
  selector:
    text: {}

# Apparaten/switches
sw_octagon:
  name: Octagon (SF8008) switch
  selector:
    entity:
      domain: switch
sw_f1:
  name: F1/Smartbox switch
  selector:
    entity:
      domain: switch
sw_jbl:
  name: JBL switch
  selector:
    entity:
      domain: switch
sw_sofa:
  name: Zitbank switch
  selector:
    entity:
      domain: switch
sw_kast:
  name: Kastlampen switch
  selector:
    entity:
      domain: switch
sw_kast_low:
  name: Lage kastlamp switch
  selector:
    entity:
      domain: switch

# Gedrag/robuustheid
delay_source_fill_seconds:
  name: Wacht (sec) na TV aan voordat bron wordt gelezen
  default: 5
  selector:
    number:
      min: 0
      max: 20
      unit_of_measurement: s
      mode: slider

keep_on_ping_minutes:
  name: Interval (min) om JBL/Zitbank aan te houden zolang TV aan is
  default: 10
  selector:
    number:
      min: 1
      max: 60
      unit_of_measurement: min
      mode: slider

force_source_retry_count:
  name: Aantal retries om naar Octagon-bron te schakelen
  default: 3
  selector:
    number:
      min: 1
      max: 5
      mode: slider

force_source_retry_delay:
  name: Wacht (sec) tussen retries
  default: 2
  selector:
    number:
      min: 1
      max: 10
      unit_of_measurement: s
      mode: slider

mode: restart

-----------------------------------------------------------

Triggers (de blueprint bundelt alle scenario’s)

-----------------------------------------------------------

trigger:

A) TV gaat aan (scene bepalen op basis van bron)

  • id: tv_on
    platform: state
    entity_id: !input tv
    to: ‘on’

B) Bronwijziging (om streaming verlaten op te vangen)

  • id: source_changed
    platform: state
    entity_id: !input tv
    attribute: source

C) Octagon switch aangezet → forceer bron

  • id: octagon_on
    platform: state
    entity_id: !input sw_octagon
    to: ‘on’

D) TV uit

  • id: tv_off
    platform: state
    entity_id: !input tv
    to: ‘off’

E) Sunrise/Sunset events

  • id: sunrise
    platform: sun
    event: sunrise
  • id: sunset
    platform: sun
    event: sunset

F) Keep-alive: JBL/Zitbank aanhouden zolang TV aan

  • id: keep_on_tick
    platform: time_pattern
    minutes: “/{{ iif((!input keep_on_ping_minutes) == 0, 10, (!input keep_on_ping_minutes)) }}”

-----------------------------------------------------------

Variabelen

-----------------------------------------------------------

variables:
tv: !input tv
streaming_sources: !input streaming_sources
octagon_source: !input octagon_source
f1_source: !input f1_source

-----------------------------------------------------------

Acties

-----------------------------------------------------------

action:

  • choose:

    ========== CASE 1: TV gaat aan ==========

    • conditions:

      • condition: template
        value_template: “{{ trigger.id == ‘tv_on’ }}”
        sequence:

      Wachten tot bron gevuld

      • delay:
        seconds: !input delay_source_fill_seconds

      Altijd JBL + Zitbank aan

      • service: switch.turn_on
        target:
        entity_id:
        - !input sw_sofa
        - !input sw_jbl

      F1 altijd uit

      • service: switch.turn_off
        target:
        entity_id: !input sw_f1

      Octagon uit als bron streaming is, anders aan

      • choose:
        • conditions:
          • condition: template
            value_template: >
            {{ state_attr(tv, ‘source’) in streaming_sources }}
            sequence:
          • service: switch.turn_off
            target:
            entity_id: !input sw_octagon
            default:
        • service: switch.turn_on
          target:
          entity_id: !input sw_octagon

      Lampen alleen na zonsondergang

      • choose:
        • conditions:
          • condition: sun
            after: sunset
            sequence:
          • service: switch.turn_on
            target:
            entity_id:
            - !input sw_kast
            - !input sw_kast_low

    ========== CASE 2: Streaming/F1 verlaten ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘source_changed’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’

      we kwamen VAN streaming óf F1

      • condition: template
        value_template: >
        {{ trigger is not none and trigger.from_state is not none and
        (trigger.from_state.state in streaming_sources or
        trigger.from_state.state == f1_source) }}

      we ZIJN nu NIET in streaming en NIET al op octagon_source

      • condition: template
        value_template: >
        {{ trigger is not none and trigger.to_state is not none and
        (trigger.to_state.state not in streaming_sources) and
        (trigger.to_state.state != octagon_source) }}
        sequence:

      Octagon aan, F1 uit

      • service: switch.turn_on
        target:
        entity_id: !input sw_octagon
      • service: switch.turn_off
        target:
        entity_id: !input sw_f1

      Lampen na zonsondergang

      • choose:
        • conditions:
          • condition: sun
            after: sunset
            sequence:
          • service: switch.turn_on
            target:
            entity_id:
            - !input sw_kast
            - !input sw_kast_low

    ========== CASE 3: Octagon switch gaat aan → forceer bron met retry ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘octagon_on’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’
        sequence:
      • delay:
        seconds: !input force_source_retry_delay
      • repeat:
        count: !input force_source_retry_count
        sequence:
        - service: media_player.select_source
        target:
        entity_id: !input tv
        data:
        source: !input octagon_source
        - delay:
        seconds: !input force_source_retry_delay
        - choose:
        - conditions:
        - condition: template
        value_template: >
        {{ state_attr(tv, ‘source’) == octagon_source }}
        sequence:
        - stop: “Octagon-bron geselecteerd”

    ========== CASE 4: TV uit of sunrise ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id in [‘tv_off’, ‘sunrise’] }}”
        sequence:
      • choose:

        TV uit → alles uit

        • conditions:
          • condition: template
            value_template: “{{ trigger.id == ‘tv_off’ }}”
            sequence:
          • service: switch.turn_off
            target:
            entity_id:
            - !input sw_sofa
            - !input sw_jbl
            - !input sw_kast
            - !input sw_kast_low
            - !input sw_octagon

        Sunrise → alleen lampen uit

        • conditions:
          • condition: template
            value_template: “{{ trigger.id == ‘sunrise’ }}”
            sequence:
          • service: switch.turn_off
            target:
            entity_id:
            - !input sw_kast
            - !input sw_kast_low

    ========== CASE 5: Sunset terwijl TV aan → lampen aan ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘sunset’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’
        sequence:
      • service: switch.turn_on
        target:
        entity_id:
        - !input sw_kast
        - !input sw_kast_low

    ========== CASE 6: Keep-alive (zolang TV aan is: JBL/Zitbank aan) ==========

    • conditions:
      • condition: template
        value_template: “{{ trigger.id == ‘keep_on_tick’ }}”
      • condition: state
        entity_id: !input tv
        state: ‘on’
        sequence:
      • service: switch.turn_on
        target:
        entity_id:
        - !input sw_sofa
        - !input sw_jbl

    default: