How to start automatically my System Alarm at night?

Hi, I wish to arm my System Alarm automatically every night (from 23:30 to 06:00) in “home” mode if my smartphone is connected to my router.
Then I created this automation code… but it do not arm the alarm… why???
What is wrong?

  - alias: system alarm home automatic on night
    trigger:
      - platform: state
        entity_id: device_tracker.samsung_s8_wifi
        to: 'home'
      - platform: state
        entity_id: device_tracker.samsung_s8_bt
        to: 'home'
    condition:
      condition: and
      conditions:
        - condition: time
          before: '06:00:00'
          after: '23:30:00'
        - condition: state
          entity_id: alarm_control_panel.ha_alarm
          state: 'disarmed'
    action:
      service: alarm_control_panel.alarm_disarm
      data: {"entity_id":"alarm_control_panel.ha_alarm","code":"1234"}

Any help please…

You have your triggers and conditions backwards:

From what I gather you want to do is for the alarm system to be armed (action) at 23:30 (trigger) but only if your phone is home (condition).

Is that correct?

I think you will have to create another automation to disarm it at 06:00.

YES it is correct.

Now I edited it… with two automations
Now in Italy is 11:45
I configured to arm alarm after 11:00 … I restarted home assistant… but it do not arm alarm in home mode

  - alias: system alarm home automatic on
    trigger:
      - platform: state
        entity_id: device_tracker.samsung_s8_wifi
        to: 'home'
      - platform: state
        entity_id: device_tracker.samsung_s8_bt
        to: 'home'
    condition:
        - condition: time
          after: '11:00:00'
        - condition: state
          entity_id: alarm_control_panel.ha_alarm
          state: 'disarmed'
    action:
      service: alarm_control_panel.alarm_disarm
      data: {"entity_id":"alarm_control_panel.ha_alarm","code":"1234"}  

  - alias: system alarm home automatic off
    trigger:
      - platform: state
        entity_id: device_tracker.samsung_s8_wifi
        to: 'home'
      - platform: state
        entity_id: device_tracker.samsung_s8_bt
        to: 'home'
    condition:
        - condition: time
          after: '06:00:00'
    action:
      service: alarm_control_panel.alarm_disarm
      data: {"entity_id":"alarm_control_panel.ha_alarm","code":"1234"}

…but it do not works…

you still didn’t change the triggers and conditions around.

if you look at the code you should see that the time that you want it to fire is going to be the trigger:

trigger:
  platform: time
  hours: 23
  minutes: 30
  seconds: 00

but you only want it to come on if the condition is met that your phone is home:

condition:
  condition: state
  entity_id: device_tracker.samsung_s8_wifi
  state: 'home'

You’ll have to fill in the rest of the details but this should be enough to guide you in the right direction.

Ohhh… now it works fine!

Thank you finity

You’re welcome. Glad I could help. :smiley:

We’ve all been noobs at one point.

Ahahah you’ve right! :smile: