Skip to content

Instantly share code, notes, and snippets.

@jahir
Last active March 9, 2020 11:38
Show Gist options
  • Save jahir/3ff1b60b60d0d0a00c0cb274d6355f97 to your computer and use it in GitHub Desktop.
Save jahir/3ff1b60b60d0d0a00c0cb274d6355f97 to your computer and use it in GitHub Desktop.
power off after %mem1% minutes with less than %mem2% W
# first turn all rules off
backlog rule1 0; rule2 0; rule3 0
# PC, laptop
backlog mem1 5; mem2 60
# laser printer
backlog mem1 30; mem2 600
# set/reset ruletimer for power off depending on power usage
rule1
on Energy#Power<%mem1% do ruletimer1 %mem2% endon
on Energy#Power>%mem1% do ruletimer1 0 endon
# power off when ruletimer1 fires,
# enable/disable rule1 and ruletimer1 when power1 turns on/off.
rule2
on Rules#Timer=1 do backlog Power1 off; Ruletimer1 0 endon
# cascading with 2 power outlets:
# PC on Power1 with monitor on Power2:
# turn Power1 on when Power2 is turned on,
# turn Power2 off when Power1 is turned off
rule2
on Rules#Timer=1 do power1 0 endon
on power1#state=1 do backlog delay 5; rule1 1 endon
on power1#state=0 do backlog power2 0; Rule1 0 endon
on power2#state=1 do backlog power1 1; Rule1 1 endon
# re-activate rules. rule1 must be one-shot
backlog rule1 5; rule1 1; rule2 1
###############################################################################
# old style
rule1
on power1#state=0 do power2 off endon
on power1#state=1 do backlog rule2 on; ruletimer2 20 endon
on power2#state=1 do power1 on endon
on rules#timer=1 do rule2 on endon
on rules#timer=2 do power1 off endon
on system#boot do rule2 on endon
rule2
on Energy#Power>5 do backlog ruletimer1 60; ruletimer2 120 endon
on Energy#Power>5 do rule2 off endon
rule2
on Energy#Power>5 do backlog ruletimer1 10; ruletimer2 20; rule2 off endon
###############################################################################
# old style with variables
backlog rule1 0; rule2 0; rule3 0
backlog mem1 5; mem2 60; mem3 90
rule1
on power1#state=1 do backlog rule2 on; ruletimer2 endon
on rules#timer=1 do rule2 on endon
on rules#timer=2 do power1 off endon
rule2
on Energy#Power>5 do backlog ruletimer1 10; ruletimer2 20; rule2 off endon
rule3
on power1#state=0 do power2 off endon
on power2#state=1 do power1 on endon
backlog rule2 5; rule1 1; rule2 1; rule3 1
# set syslog host
backlog LogHost mylogserver; SysLog 2
# http://<ip>/cm?cmnd=Power%20TOGGLE
curl http://tasmota-xxxx/cm?cmnd=backlog%20LogHost%20mylogserver%3b%20SysLog%202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment