#Automation stops working the next day

1 messages · Page 1 of 1 (latest)

karmic shale
#

Hi.

I made an automation (noob here) that would turn on my lights (light.zigbee_controller_staanlamp_zolder) if my PC is turned on after 8pm30. Once the PC is turned off, lights should turn off after about a minute.

I'm using Ping and made a ping to my PC ip.

This is the automation:

description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.pc_vinnie_ping
conditions:
  - condition: time
    after: "20:30:00"
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.pc_vinnie_ping
            state: "on"
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: light.zigbee_controller_staanlamp_zolder
      - conditions:
          - condition: state
            entity_id: binary_sensor.pc_vinnie_ping
            state: "off"
        sequence:
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.zigbee_controller_staanlamp_zolder
mode: single

What am I doing wrong here?

dense umbra
#

Describe in which conditions it is not working.

karmic shale
dense umbra
#

Did you confirm the ping sensor transitioned from off to on at that time?

karmic shale
#

So PC was on and showed connected to ping from 8am till 1630 and from 20:00 (8pm) until now

dense umbra
#

So you said you turned on the PC at 9pm, but this says Verbonden at 8pm?

karmic shale
#

However, I still wonder why it didn't turn on today (the light) even though the pc was running

karmic shale
#

@dense umbra Could it be that, if the pc is already on before 8.30pm that it doesn't work?

dense umbra
#

Yes that is exactly how your automation is written.

karmic shale
#

Oh, anyway to make it turn on if the status was already connected at 8.30 as well as if it turns on after 8.30?

dense umbra
#

Add a time trigger at 8:30. Add a condition that the sensor is on.

#

As you have it, the automation only runs when the sensor changes from off->on.
You need to tell it to run at 8:30.

karmic shale
#

Thanks!

arctic wharf
#

Also note, you indirectly have 0:00 as "end time". So if you turn off the PC after 0:00 nothing will happen.

karmic shale
arctic wharf
#

just add the time condition to the condition block of the "turn on" option in the chooser and remove it from the whole automation.

Next tip, just add a seperate trigger for on and off. That way you can add a "for 1 minute" to the off trigger and get rid of the delay. Because if you now turn off the PC (restart of whatever) and turn it on again it will turn off the lights 😄 But if you only trigger when the PC is off for 1 minute, that trigger will not fire when you do a quick power cycle.

karmic shale
#

So two different automations?

Sorry, pretty new at this

arctic wharf
#

no, single automation with two triggers. With the choose you can pick what you do. Let me give it a go

karmic shale
#

This is what I got with chatgpt's help 😄

description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.pc_vince_ping
    to: "on"
  - platform: state
    entity_id: binary_sensor.pc_vince_ping
    to: "off"
    for: "00:01:00"  # Only trigger when PC is off for 1 minute
  - platform: time
    at: "20:30:00"  # Checks if PC was already on at 2030
condition:
  - condition: or
    conditions:
      - condition: time
        after: "20:30:00"
        before: "23:59:59"
      - condition: time
        after: "00:00:00"
        before: "06:00:00"
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.pc_vince_ping
            state: "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.zigbee_controller_staanlamp_zolder
      - conditions:
          - condition: state
            entity_id: binary_sensor.pc_vince_ping
            state: "off"
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.zigbee_controller_staanlamp_zolder
mode: single
arctic wharf
#

pretty close, but still will not turn off the light after 6:00 and the time condition can span midnight already for like 3 years or so. I would do:

#

I would do something like:

#
alias: Licht zolder = vinnie PC status
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.pc_vinnie_ping
    to: "on"
    id: Aan
  - trigger: time
    at: "20:30:00"
    id: Aan
  - trigger: state
    entity_id:
      - binary_sensor.pc_vinnie_ping
    to: "off"
    id: Uit
    for:
      hours: 0
      minutes: 1
      seconds: 0
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Aan
          - condition: state
            entity_id: binary_sensor.pc_vince_ping
            state: "on"
          - condition: time
            after: "20:30:00"
            before: "06:00:00"
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: light.zigbee_controller_staanlamp_zolder
    default:
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.zigbee_controller_staanlamp_zolder
mode: single
#

Whole trigger id and trigger condition can be left out. But I think it makes it more clear what it does and can help to expand it. At least expand the knowledge 😄

karmic shale
#

Sweet, thanks! Still learning a bunch!

arctic wharf
#

And you could add a trigger @ 6:00:00 as well. That would turn off the light when the PC is still on at that time. Or swap the times for the angle of the sun. That way it will turn on quicker in the winter

#

options options options

karmic shale
arctic wharf
#

yeah, the condition: trigger isn't set when you run it manually. So a condition with that will never be true when you do a manual run