Template switch triggered at boot

Hi all,

I have different template switch (for harmony hub and broadcast link).

I noticed looking at logbook that when I reboot HA they got triggered without any reason causing TV to switch on (or switch off if already on).

Can someone please support me?

Please post the automations that are triggering, then people will be able to help. :slight_smile:

I have the doubt that is not related to any automation.

Because no automation got triggered looking at logbook!

Moreover today one of my tasmotized cover started closing without any request!!! I’M PRETTY SCARED!

look at the logbook:

17:35
xiaomimi6 Screen Sensor turned off
17:35
redminote7 Screen Sensor turned off
17:35
xiaomimi6 Screen Sensor turned on
17:35
xiaomimi6 Screen Sensor turned off
17:35
redminote7 Screen Sensor turned on
17:35
redminote7 Screen Sensor turned off
17:35
redminote7 Screen Sensor turned on
17:35
Bagno Principale changed to idle
17:35
Bagno Secondario changed to idle
17:35
Google Home Mini changed to idle
17:35
Google Home Mini changed to playing
17:35
Bagno Principale changed to playing
17:35
Bagno Secondario changed to playing
17:34
xiaomimi6 Screen Sensor turned on
17:31
redminote7 Screen Sensor turned off
17:30
Tapparella Cucina Su turned off
17:30
redminote7 Screen Sensor turned on
17:30
Tapparella Cucina Su turned on
17:30
Tapparella Cucina Giù turned off
17:30
Tapparella Cucina Giù turned on
17:30
Bagno Principale changed to idle
17:30
Bagno Secondario changed to idle
17:30
Google Home Mini changed to idle
17:30
Bagno Principale changed to playing
17:30
Bagno Secondario changed to playing
17:30
Google Home Mini changed to playing
17:29
HA runtime changed to 15 hours, 29 minutes
17:29
xiaomimi6 Available Status changed to 2019-04-16 17:29:00
17:29
redminote7 Available Status changed to 2019-04-16 17:29:00
17:29
Time changed to 17:29
17:27
last motion changed to Cucina
17:27
Cucina turned on
17:27
redminote7 Screen Sensor turned off

as you may see no phone was active when the cover started closing!

So far this puzzle contains:

  • a template sensor
  • a phone
  • an automation
  • a log

How about sharing the configuration for, at the very least, the template sensor?

Stai esagerando, si? :wink:

Well,

I undestand that it may seems too much without the context so, here it is:

My wife was in the balcony seconds before the covers starts closing, and my dauther (5 months old) was inside the house, as well as her smartphone.

So this is what scares me: technology must semplify and make life safier. If my covers starts closing without a reason well, it’s not ok.

Regardind the template switch (not sensor) here they are:

switch:
    - platform: broadlink
      host: xxxxxxxxxx
      mac: 'xxxxxxxxxxx'
     # # type: rm_mini
      timeout: 15
      switches:
        togglestereostudio:
          friendly_name: "Stereo Studio"
          command_on: 'JgBYAAABKJMTEhIUERMTNxI4EjgSExI3ExMRFBISExISFBISExISExI4EhMSOBI3EzgSEhMSEjgTEhI4ExISExITEzcSOBITEgAFswABKEoSAAxWAAEoShIADQU='
          command_off: 'JgBYAAABKJMTEhIUERMTNxI4EjgSExI3ExMRFBISExISFBISExISExI4EhMSOBI3EzgSEhMSEjgTEhI4ExISExITEzcSOBITEgAFswABKEoSAAxWAAEoShIADQU='

and here it is the automation triggered at boot:

- alias: "Studio in riproduzione"
  # hide_entity: true
  # initial_state: 'on'
  trigger:
    - platform: state
      entity_id: media_player.studio
      to: 'playing'
      for:
        seconds: 2
    - platform: state
      entity_id: media_player.casa
      to: 'playing'
      for:
        seconds: 2
  action:
      service: switch.turn_on
      entity_id: switch.togglestereostudio

         
- alias: "Studio in pausa-stoppato"
  # hide_entity: true
  # initial_state: 'on'
  trigger:
    - platform: state
      entity_id: media_player.studio
      #from: 'playing'
      to: 'off'
      for:
        minutes: 2
    - platform: state
      entity_id: media_player.casa
      #from: 'playing'
      to: 'off'
      for:
        minutes: 2
  action:
      service: switch.turn_off
      entity_id: switch.togglestereostudio

I would put some money on the second automation triggering after restart. Putting the from state back in would be a good start.

- alias: "Studio in pausa-stoppato"
  # hide_entity: true
  # initial_state: 'on'
  trigger:
    - platform: state
      entity_id: media_player.studio
      from: 'playing'
      to: 'off'
      for:
        minutes: 2
    - platform: state
      entity_id: media_player.casa
      #from: 'playing'
      to: 'off'
      for:
        minutes: 2
  action:
      service: switch.turn_off
      entity_id: switch.togglestereostudio

Your template switch is just a broadlink switch. Copied the wrong thing?

I’m sorry to hear that. However, the automations you’ve provided don’t appear to have anything to do with a cover. Can we see that one?

That’s the point! I have no automation for covers!

Maybe some infared devices triggered your broadlink?

I checked disabling automation for few days. No ghost triggering. So It’s definitely related to HA broadlink switch.

Then answering for @walrus_parka:

I have the same issue with broadlink switch and with template switch for harmony hub:

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 %} 

Here the issue is double:

it happens that when I reboot HA the tv switch off. And then I noticed that tv off scripts I don’t know why toggle also other devices than the single tv.

Is your cover controlled by MQTT? Do you have retain: true?

Here’s the cover code.

Retain is commented:

cover:
  - platform: mqtt
    name: "Tapparella Cucina"
    availability_topic: "tapparellacucina/tele/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    position_topic: "tapparellacucina/stat/SHUTTER1"
    position_open: 100
    position_closed: 0
    set_position_topic: "tapparellacucina/cmnd/shutterposition"
    value_template: "{{ value | int }}"
    command_topic: "tapparellacucina/cmnd/backlog"
    payload_open: "SHUTTEROPEN"
    payload_close: "SHUTTERCLOSE"
    payload_stop: "SHUTTERSTOP"
    # retain: false
    # optimistic: false
    qos: 0

I doubt it’s related to the other switch. Turning off the automation was not a conclusive test if the true cause is unrelated to Home Assistant.

I believe the so-called ‘ghost triggering’ is caused by the same thing that causes all other complaints about ‘ghost triggering’, namely the incorrect use of either retain: true or incorrect configuration of the device’s startup behavior.

Did your configuration for cover.tapparella_cucina ever use retain: true? If it never did, skip to the next paragraph.

If it initially did, and then you changed it to retain: false, the broker continues to retain messages for tapparellacucina/cmnd/backlog (the command topic). To stop it from doing that, you have to purge (delete) retained messages from that topic. MQTT Explorer makes it easy to delete retained messages. You can also delete a retained message by publishing an empty string to the topic (you can use Home Assistant’s MQTT page to do that).

If it never did, check how you programmed the device’s firmware to behave when the device starts. It can be instructed to turn the load on, off, or restore to its previous state. Loss of WiFi, or connection to the MQTT broker, or a power-failure can cause the device to restart.

OK I used HA frontend to publish an empty topic. How can I check if I done it correctly?

Use MQTT Explorer as @123 suggested.

I have installed mqttbox on my win10 PC.

I suscribed to that topic, waited, but I can’t see any message.

The recommendation… twice was MQTT EXPLORER but your choice!