Possible bug in group visibility automation

Hi,

So I’ve followed this guide to toggle group visibility
The thing is when restarting HA the group is visible when it’s not expected to be
I checked that the automation is indeed being triggered and that the occasion sensor is in the correct state so I can’t make any sense out of it


- alias: Work afternoon
  trigger:
    - platform: state
      entity_id: sensor.occasion
    - platform: homeassistant
      event: start
  action:
    service: script.group_visibility
    data:
      entity_id: group.time_to_home
      cond: sensor.occasion
      visible_state: 'work_afternoon'

2017-11-20 12:18:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.occasion=weekday; friendly_name=Occasion @ 2017-11-20T12:18:27.259553+02:00>, old_state=None, entity_id=sensor.occasion>
Line 1033: 2017-11-20 12:18:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: message=has been triggered, domain=automation, name=Work afternoon, entity_id=automation.work_afternoon>
Line 1036: 2017-11-20 12:18:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=script, service_data=visible_state=work_afternoon, cond=sensor.occasion, entity_id=group.time_to_home, service_call_id=1971267312-20, service=group_visibility>

While the relevant parts of the scripts are these

# Matching is done from top to bottom
week_days = [6, 7, 0, 1, 2, 3]
weekend = [4, 5]

OCCASIONS = [
    # More specific occasions
    mk_occasion('work_morning', '06:00:00', '08:00:00', week_days),
    mk_occasion('work_afternoon', '14:00:00', '18:00:00', week_days),

    # General matching
    mk_occasion('weekday', '00:00:00', '23:59:59', week_days),
    mk_occasion('weekend', '00:00:00', '23:59:59', weekend)

]

Any help is appreciated here…

I’ve opened the following issue on GitHub, I believe it’s a real bug, I’ve merged both automations to one to make this work :

And ended up merging both automations to get this functionality to work

- alias: Traffic times visibility
  trigger:
    - platform: state
      entity_id: sensor.occasion
    - platform: homeassistant
      event: start
  action:
    - service: script.group_visibility
      data:
        entity_id: group.time_to_work
        cond: sensor.occasion
        visible_state: 'work_morning'
    - service: script.group_visibility
      data:
        entity_id: group.time_to_home
        cond: sensor.occasion
        visible_state: 'work_afternoon'