Can't get nest/time/location trigger to work

I realy don’t know what is wrong with my configuration - part of my automations work, mostly those which turn something off… can somebody tell me where’s the error?


  • Sonoff switch with AFE Firmware, configured with MQTT
  • Nest 3rd GEN
  • latest @ RaspberryPi2 connected via LAN

ingredients for automation triggering:

  • switch.swc_choinka: for switching lights on and off. MQTT platform, topic, payload etc. everything configured correctly [works if switched on/off manually]
  • binary_sensor.bns_nest_away: correctly configured with value_template: “{{ is_state_attr(‘climate.living_room_salon’, ‘away_mode’, ‘on’) }}” [when checked in “states” browser - shows correct values]
  • group.grp_domownicy: people tracked via nmap and gpslogger, when someone’s at home - shows correct “home” value
  • notify.huncbot: telegram bot configured with broadcast mode, just for testing - I wanted to be double-sure that automation is fully run

what I want:

  • turn on lights AFTER 7:30am but BEFORE 1:00am, if nest “away” mode is off and/or if somebody is at home, but ONLY between 15th December and 15th January, then tell me about it via telegram

and now automation config - turning on the lights DOESN’T work, I don’t know why…

alias: turn_on_the_lights
  - platform: state
    entity_id: binary_sensor.bns_nest_away
    to: "off"
  - platform: time
    at: "07:30:00"
  - platform: state
    entity_id: group.grp_domownicy
    to: 'home'
  condition: and
    - condition: template
      value_template: '{{ ( now().month == 12 and ( now().day >= 15 )) or ( now().month == 1 and now().day <= 15 ) }}'
    - condition: time
      before: "01:00:00"
    - condition: or
        - condition: state
          entity_id: binary_sensor.bns_nest_away
          state: "off"
        - condition: state
          entity_id: group.grp_domownicy
          state: 'home'
  - service: switch.turn_on
    entity_id: switch.swc_choinka
  - service: notify.huncbot
      message: 'lights are now ON!'

and configuration for turning the lights OFF - works good:

alias: turn_off_the_lights
  - platform: template
    value_template: "{{ is_state_attr('climate.living_room_salon', 'away_mode', 'on') }}"
    ### ^^^ first I've tried another way of testing the away settings
    ### where "living_room_salon" is the name of my main nest thermostat
    ### - both gives good answer in the state browser
    ### but so there's no special difference which one I use
  - platform: time
    at: "01:00:00"
  - service: switch.turn_off
    entity_id: switch.swc_choinka
  - service: notify.huncbot
      message: 'lights are OFF now!'

I gave up, don’t know what I did wrong… why turning the lights is not working? :frowning:

Do you get the telegram notification?

nope. the thing is, that the automation won’t start at all… don’t know why

Can I just confirm these are either in separate files merged as a list, or if they’re in the same file you do have a hyphen before the word alias on both? If not that’s the problem.

If so there’s a conflict with your triggers and conditions so they’re always not true.

I suspect the conditions, but nothing immediately jumps out at this time of night. Comment them out and reintroduce them one by one until it stops working.

oh, yes, I forgot to mention that - all automations are in separate files, merged with

automation: !include_dir_list automations/

so I guess, that hyphen before alias isn’t needed at all?

and as I’m still relatively new with home assistant [been playing “seriously” for about a week or two now], I need to ask one additional thing, just to clear my doubs out:
when adding triggers, ANY of them alone, can start the action and there is no need to all of the triggers be positive, right?

Yeah, they’re effectively added by the include, so that’s not your issue.

Yeah, triggers are like an ‘or’, so it will trigger as and when each of them occur. Hence why I suspect it’s the conditions that are the problem but I’ll be honest I scanned your post for ages trying to find the conflict and it beat me. I’m hoping it’s just tired eyes and not me losing my touch :smile:

As I say, comment them out and reintroduce them one at a time. Or another thing I sometimes do is write the logic of the conditions down and pick through it one by one with a load of whitespace between each one to make sure it matches what I’ve written down before removing the whitespace again. Random, but it’s worked a few times. Hard to spot errors in large chunks of text :wink:

Argggggggghhhhh, just as I was about to give up I think I’ve spotted the problem!

You can’t be after 7.30 AND before 1am on the same day. (your condition will only become true if one of the triggers occurs between midnight and 1am).

You’ll need a different method to determine the time condition (like an input boolean).

thanks for fighting this battle with me at such an unhuman part of the day :wink: [it’s 1am at my place ;)]

yep, will try, tomorrow probably. today just few more tweaks in dashboard and it’s time to bed :wink:

aaaargh, true. I need to rethink that then… THANKS!.. but - I’ve got another automation, which looks almost the same - just without the “after 7:30” and… it’s not working anyway ;( gotta try to comment them out as you said, and play with one at a time. will check it and report tomorrow :slight_smile:

1 Like

rethinked, redesigned slightly and… working :wink:

@anon43302295 - just like you wrote, time condition needed to be changed.
while for humans it’s easy to think about “the time between 7am and 1am” [we can consider it simply as one long day], home assistant can’t deal with that out of the box. so after few trials and errors, instead of tinkering the way to recognize 1am as the end of the day [counted after 7am], I just thought, that I really don’t need to make a time condition “before 1am”…

another automation already turns off lights at 1am, and there is a very little chance, that my home between midnight and 1am will be empty and waiting for someone to come back in that very hour, so I just simply changed te “before” time:

- condition: time
  after: "07:30:00"
  before: "23:59:00"

tested with different hours [like: now ;)] and works fine. so I guess tomorrow morning, the lights should be on, when I’ll get up :slight_smile:

…and that little change costed me earlier few hours of looking at the code and understanding nothing… :smiley:

1 Like

Glad you got sorted :+1: