#Automation for a office lamp to turn on, when the PC is on and its dark outside

1 messages · Page 1 of 1 (latest)

sinful schooner
#

Hey,
i want an automation that turns on my office lamp, when my pc is on and its dark outside (don't got a light level sensor yet).
Here is my actual automation:

description: ""
mode: single
triggers:
  - minutes: /1
    trigger: time_pattern
  - type: turned_on
    device_id: d28db8e23301483c2a1bb0b2b832ef50
    entity_id: 828b89bbee6dd4fb17a161c2b087f61c
    domain: switch
    trigger: device
conditions:
  - condition: sun
    before: sunrise
    after: sunset
    after_offset: "-00:45:00"
  - condition: or
    conditions:
      - condition: device
        type: is_on
        device_id: d28db8e23301483c2a1bb0b2b832ef50
        entity_id: 828b89bbee6dd4fb17a161c2b087f61c
        domain: switch
actions:
  - type: turn_on
    device_id: 66fe6f3c8873df09795ecce41c2441a9
    entity_id: light.tl01
    domain: light```

The issue is, when i manual turn off the lamp, it turns automatically on again, because the trigger still works.
It should only trigger once, per pc on (f.e. when i turn the PC off at 22:00 and on again at 23:00, the lamp should go on, even when i manual turned off the lamp at 21:55).

Has anyone a good way to do this?
real verge
ivory dune
fresh badge
#

I agree with the comments already. This code doesn’t implement the sun elevation change but you should be able to do that easily.

description: ""
mode: single
triggers:
  - trigger: state
    entity_id: switch.pc
    from: "off"
    to: "on"
  - trigger: sun
    event: sunset
    offset: "-00:45:00"
conditions:
  - condition: sun
    before: sunrise
    after: sunset
    after_offset: "-00:45:"
  - condition: state
    entity_id: switch.pc
    state: "on"
actions:
  - action: light.turn_on
    target:
      entity_id: light.tl01
sinful schooner
#

Sorry guys, i totally forgot about this somehow 😅

sinful schooner
#

I am not very good with those things, i try this for now:

alias: Office lamp v2
description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - switch.tp03
    from: "off"
    to: "on"
  - trigger: state
    entity_id:
      - sun.sun
    attribute: elevation
    to: "-4"
conditions:
  - condition: state
    entity_id: switch.tp03
    state: "on"
  - condition: state
    entity_id: sun.sun
    attribute: elevation
    state: "-4"
actions:
  - action: light.turn_on
    target:
      entity_id: light.tl01
fresh badge
#

For elevation you’ll want to use a “numeric state” trigger and condition instead of a “state” trigger

sinful schooner
# fresh badge For elevation you’ll want to use a “numeric state” trigger and condition instead...

Hmmm, does not seem to work:

description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.tp03
    from: "off"
    to: "on"
  - trigger: numeric state
    entity_id:
      - sun.sun
    attribute: elevation
    to: "-4"
conditions:
  - condition: state
    entity_id: switch.tp03
    state: "on"
  - condition: numeric state
    entity_id: sun.sun
    attribute: elevation
    state: "-4"
actions:
  - action: light.turn_on
    target:
      entity_id: light.tl01
    data: {}
mode: single
#

nevermind its "numeric_state"

fresh badge
#

yes that, plus you will need to use above or below instead of state

sinful schooner
#

do i need a above?

fresh badge
#

I think you want to trigger when the sun elevation drops below -4 degrees right? So you would want below

sinful schooner
#

looks like so now:

description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.tp03
    from: "off"
    to: "on"
  - trigger: numeric_state
    entity_id:
      - sun.sun
    attribute: elevation
    below: -4
conditions:
  - condition: state
    entity_id: switch.tp03
    state: "on"
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: -4
actions:
  - action: light.turn_on
    target:
      entity_id: light.tl01
    data: {}
mode: single
fresh badge
#

looks right to me