Script triggered without reason

HI,

I don’t know why without any reason scripts got triggered:
image

Those script are based on this post

You really should share your script and automations.
A script will not start on its own, it’s called somewhere.
You’ve got lots of stuff happening nearly at the same time. I’d bet you my bottom dollar one of these events calls the script…

You are right.

Below all the code (scripts and automations). Now code is all commented.

sensor:

  • platform: template
    sensors:
    harmony_activity:
    friendly_name: ‘Harmony Status’
    value_template: >
    {% if is_state(“remote.harmony_hub”, ‘on’) %}
    {{ states.remote.harmony_hub.attributes.current_activity }}
    {% else %}
    PowerOff
    {% endif %}

  • platform: history_stats
    name: TV accesa
    entity_id: media_player.tv_soggiorno
    state: ‘playing’
    type: time
    start: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
    end: ‘{{ now() }}’

  • platform: template
    sensors:
    sorgentetvsoggiorno:
    value_template: ‘{{ states.media_player.tv_soggiorno.attributes[“source”] }}’
    friendly_name: ‘TV Soggiorno’

switch:

  • platform: template
    switches:
    tvsoggiorno_switch:
    friendly_name: “TV Soggiorno”
    value_template: “{{ is_state(‘remote.harmony_hub’, ‘on’) }}”
    turn_on:
    service: script.turn_on
    data:
    entity_id: script.tv
    turn_off:
    service: script.turn_on
    data:
    entity_id: script.tvoff
    icon_template: >
    {% if is_state(‘remote.harmony_hub’, ‘on’) %}
    mdi:television-classic
    {% else %}
    mdi:television-classic-off
    {% endif %}

  • platform: template
    switches:
    plex_switch:
    friendly_name: “Plex”
    value_template: “{{ is_state(‘remote.harmony_hub’, ‘on’) }}”
    turn_on:
    service: script.turn_on
    data:
    entity_id: script.Plex
    turn_off:
    service: script.turn_on
    data:
    entity_id: script.tvoff

  • platform: template
    switches:
    netflix_switch:
    friendly_name: “Netflix”
    value_template: “{{ is_state(‘remote.harmony_hub’, ‘on’) }}”
    turn_on:
    service: script.turn_on
    data:
    entity_id: script.netflix
    turn_off:
    service: script.turn_on
    data:
    entity_id: script.tvoff

  • platform: template
    switches:
    primevideo_switch:
    friendly_name: “Prime Video”
    value_template: “{{ is_state(‘remote.harmony_hub’, ‘on’) }}”
    turn_on:
    service: script.turn_on
    data:
    entity_id: script.primevideo
    turn_off:
    service: script.turn_on
    data:
    entity_id: script.tvoff

  • platform: template
    switches:
    bluray_switch:
    friendly_name: “BluRay”
    value_template: “{{ is_state(‘remote.harmony_hub’, ‘on’) }}”
    turn_on:
    service: script.turn_on
    data:
    entity_id: script.bluray
    turn_off:
    service: script.turn_on
    data:
    entity_id: script.tvoff

  • platform: template
    switches:
    vhs_switch:
    friendly_name: “VHS”
    value_template: “{{ is_state(‘remote.harmony_hub’, ‘on’) }}”
    turn_on:
    service: script.turn_on
    data:
    entity_id: script.vhs
    turn_off:
    service: script.turn_on
    data:
    entity_id: script.tvoff

media_player:

  • platform: webostv
    host: xxxxxxxxxxxxxxx
    name: TV Soggiorno
    filename: webostv.conf
    timeout: 5
    customize:
    sources:
    - livetv
    - youtube
    - netflix
    - plex
    - primevideo
    - xplay

input_select:
harmony_soggiorno:
name: Harmony Soggiorno
options:
- Spenta
- TV
- Plex
- Netflix
- Prime Video
- VHS
- BluRay
- Spotify
#initial: Spenta
icon: mdi:television-classic

script:

tv:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "38508191"

plex:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "27269375"

netflix:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "27220282"

primevideo:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "27244009"

vhs:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "27243190"

bluray:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "38687198"

spotify:

# sequence:
# - service: remote.turn_on
  # entity_id: remote.harmony_hub
  # data:
    # activity: "38640383"

tvoff:

# sequence:
# - service: remote.turn_off
  # entity_id: remote.harmony_hub

automation:

- alias: “Guarda TV from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Guarda la TV" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "TV"

- alias: “Powered off from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "PowerOff" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "Spenta"

- alias: “Plex started from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Guarda Plex" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "Plex"

- alias: “Netflix started from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Guarda Netflix" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "Netflix"

- alias: “Prime Video started from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Guarda Prime" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "Prime Video"

- alias: “VHS started from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Guarda una VHS" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "VHS"

- alias: “BluRay started from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Guarda un Film" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "BluRay"

- alias: “Spotify started from Harmony Hub”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: remote.harmony_hub
# condition:
  # condition: template
  # value_template: '{{ trigger.to_state.attributes.current_activity == "Ascolta Spotify" }}'
# action:
  # service: input_select.select_option
  # entity_id: input_select.harmony_soggiorno
  # data:
    # option: "Spotify"

- alias: “TV started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'TV'
# action:
  # service: script.turn_on
  # entity_id: script.tv

- alias: “Plex started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'Plex'
# action:
  # service: script.turn_on
  # entity_id: script.plex

- alias: “Netflix started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'Netflix'
# action:
  # service: script.turn_on
  # entity_id: script.netflix

- alias: “Prime started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'Prime Video'
# action:
  # service: script.turn_on
  # entity_id: script.primevideo

- alias: “Spotify started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'Spotify'
# action:
  # service: script.turn_on
  # entity_id: script.spotify

- alias: “BluRay started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'BluRay'
# action:
  # service: script.turn_on
  # entity_id: script.bluray

- alias: “VHS started from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'VHS'
# action:
  # service: script.turn_on
  # entity_id: script.vhs

- alias: “TV turned off from HASS”

# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'Spenta'
# action:
  # service: script.turn_on
  # entity_id: script.tvoff

it would really help if you could format your code correctly, but basically your script is turned on when you set your input_select.harmony_soggiorno to Spenta

- alias: “TV turned off from HASS”
# hide_entity: true
# # initial_state: 'on'
# trigger:
  # platform: state
  # entity_id: input_select.harmony_soggiorno
  # to: 'Spenta'
# action:
  # service: script.turn_on
  # entity_id: script.tvoff

The problem is that I DON’T do that!

For the code here it is:

https://pastebin.com/Mt1bFkAq

Here’s how to format your code on this forum:

somehow somewhere either you call the script or you set the input_select, the script won’t trigger on its own…

I wish there was shortcut or other means to quickly add this to a post. Bookmarking for now, thanks!

bit.ly/HAForumCode
:slight_smile:

1 Like