Odd automation triggering with Homematic components

I tried to use some simple automations the last days and recognized an odd behaviour:
During system start, some lights are activated - lights which are used in three automations. And that happens even if the trigger-criterias are not met. I will investigate this a little bit further and put some data into the recorder (im using include in the recorder) but can you confirm that there is no main mistake in the code. Do i overlook something?

- alias: 12.3.A - media light
  trigger:
  - platform: state
    entity_id:
      - remote.wohnzimmer
  - platform: sun
    event: sunset
  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  action:
  - condition: template
    value_template: "{{ state_attr('remote.wohnzimmer', 'current_activity') != 'PowerOff' }}"
  - service: switch.turn_on
    entity_id: switch.wz_licht_linker_schrank
  - service: switch.turn_on
    entity_id: switch.wz_licht_rechter_schrank
  - service: switch.turn_on
    entity_id: switch.wz_licht_wandregal
  - service: light.turn_on
    entity_id: light.leselampe

- alias: 4.2.A storagre room light
  trigger:
  - entity_id: binary_sensor.ar_ture
    from: 'off'
    platform: state
    to: 'on'
  action:
  - service: light.turn_on
    entity_id: light.ar_deckenlicht
- alias: 4.2.B storagre room light
  trigger:
  - entity_id: binary_sensor.ar_ture
    from: 'on'
    platform: state
    to: 'off'
  action:
  - service: light.turn_off
    entity_id: light.ar_deckenlicht

At first sight I don’t see any problems with this. :thinking:

Do you have these lights in groups? If an automation would act on the group, then it wouldn’t be directly obvious by searching for the entities in the automations.

Another option would be, that you still have an automation on the CCU that gets triggered when Home Assistant starts (like a virtual button press).

In any case, for the storage room light I would switch to “Direktverknüpfungen” if both sensor and actor are HomeMatic. I’m aware that causes a split-brain configuration. But it has the benefit that it will keep working even if Home Assistant is down for some reason. That’s why I chose to use “Direktverknüpfungen” for my basic infrastructure automations. I only use HA for automations that include 3rd party data, like the state of the sun in your first automation.

I’ll also check the groups. That’s a good hint. Thank you!

I solved the problem of the “storage room light” automations exactly as you described with “Direktverknüpfungen” at the moment. Unfortunately this is not possible with the sun and harmony triggered first automation “media light”.

Here is the update regarding that topic. I checked Logs etc. and for a short time i thought i got it. I recognized that the connection is lost during the night (as shown in the image).

Unbenannt

For that reason I changed the code:

- alias: 12.3.A - media light
  trigger:
  - platform: state
    entity_id:
      - remote.wohnzimmer
  - platform: state
    entity_id: sun.sun
  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  action:
  - condition: template
    value_template: "{{ state_attr('remote.wohnzimmer', 'current_activity') != 'PowerOff' }}"
  - condition: template
    value_template: "{{ state_attr('remote.wohnzimmer', 'current_activity') != 'Unknown' }}"
  - condition: template
    value_template: "{{ state_attr('remote.wohnzimmer', 'current_activity') != 'unavailable' }}"
  - service: switch.turn_on
    entity_id: switch.wz_licht_linker_schrank
  - service: switch.turn_on
    entity_id: switch.wz_licht_rechter_schrank
  - service: switch.turn_on
    entity_id: switch.wz_licht_wandregal
  - service: light.turn_on
    entity_id: light.leselampe

But unfortunately that did not solve the issue. Is the check for != ‘unavailable’ correct?
Further ideas?

I could not solve the problem. For that reason i try to do the same but different. Here is the next try with…

… a binary sensor:

binary_sensor:
  - platform: template
    sensors:
      harmony_medialight:
        friendly_name: "HARMONY - Media Light"
        value_template: >-
          {{ is_state_attr('remote.wohnzimmer', 'current_activity', 'TV - Dreambox')
             or is_state_attr('remote.wohnzimmer', 'current_activity', 'TV - Direct')
             or is_state_attr('remote.wohnzimmer', 'current_activity', 'TV - Fire')
             or is_state_attr('remote.wohnzimmer', 'current_activity', 'TV - BluRay')
             or is_state_attr('remote.wohnzimmer', 'current_activity', 'Radio') }}

…and an automation:

- alias: 12.3.B - media light
  trigger:
  - platform: state
    entity_id:
      - remote.wohnzimmer
  - platform: state
    entity_id: sun.sun
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: binary_sensor.harmony_medialight
      state: 'on'
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
  action:
  - service: switch.turn_on
    entity_id: switch.wz_schranklicht_linker_schrank
  - service: switch.turn_on
    entity_id: switch.wz_schranklicht_rechter_schrank
  - service: switch.turn_on
    entity_id: switch.wz_schranklicht_wandregal
  - service: light.turn_on
    entity_id: light.leselampe