hey I’m new here and am not very good at coding or such i have been trying for the better half of a day now but am unable to figure this out so i am coming for some help i know this is a lot but i hope i can get some assistance
#-------------------------------------
what i want is:
when the lastactive sensor is idle for 6 seconds it will start the automation
i will be messaged that there is a countdown running and if i move my mouse or do any activity on my pc that will refresh the sensor (the sensor doesn’t produce an on or off as far as i can tell it refreshes every second with a new name so i am tracking how long its been counting, any activity takes it back to 0 seconds and it counts up again) it will abort the automation and set it back up so its permanently looping -if idle for this many seconds then start a countdown to hibernate unless interrupted with activity-
but if it is not interrupted and left idle until the countdown finishes it will hibernate the pc
#---------------------
my issue is i cant get it to cancel the countdown/stop sending notifications if the active sensor gets updated i have tried if triggers to detect if the active bool (connected to the sensor) has been active at any point and it would send me a notification (then would restart the automation but for now just notify me) but it wont send any notifications like it wont detect if the bool has been active
this is the code i have so far (image will be below if it helps)
alias: PC Idle Countdown
description: ""
trigger:
- platform: time_pattern
seconds: /1
#triggers every second i belive that helps the automation activate closer to the given seconds in the template (it usually takes quite a while longer but i think this makes the action run nearer the idle time)
condition:
- condition: template
value_template: |-
{{ (as_timestamp(now()) -
as_timestamp(states.sensor.craigs_pc_lastactive.last_updated | default(0))) > 6 }}
#looks for idle time temporarily 6 seconds set
action:
- service: notify.craigs_pc
data:
message: PC Countdown Started - 4 mins
- parallel:
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
enabled: true
- if:
- condition: state
entity_id: input_boolean.active
for:
hours: 0
minutes: 0
seconds: 0
state: "on"
then:
- service: notify.craigs_pc
metadata: {}
data:
message: vbgjk1
- stop: ""
- service: notify.craigs_pc
data:
message: PC Countdown Started - 2 mins
- parallel:
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
enabled: true
- if:
- condition: state
entity_id: input_boolean.active
for:
hours: 0
minutes: 0
seconds: 0
state: "on"
then:
- service: notify.craigs_pc
metadata: {}
data:
message: vbgjk 2
- stop: ""
- if:
- condition: state
entity_id: input_boolean.active
state: "off"
for:
hours: 0
minutes: 5
seconds: 0
enabled: true
then:
- service: notify.craigs_pc
metadata: {}
data:
message: "off"
- service: automation.turn_off
target:
entity_id: automation.new_automationhjkg #this is to turn of the current automation when it
completes and the pc powers down i have
another automation to turn it back on when the pc is active
data:
stop_actions: true
else: []
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
mode: single
i have a Boolean that toggles when the pc is active or not so the -what would be hibernate now just an off notification- would cheak it to see if it was recently active and if so to turn off or not
i know this is a big mess i apologise like i said im new to this and tried my best but i am having a lot of trouble thanks for any help
code image