Skip to content

hs100: new schedule_off command (code included) #16

@OhSoGood

Description

@OhSoGood

Hi
Here is my small contribution to the script: a way to shedule to turn off the plug (hardcoded to 30 minutes). If called another time, the last call cancel any previous schedule and reset the schedule to 30 min.

I trigger that command when a printer finish its job, in order to turn off that printer after a while, if no other print job is launched (in which case, the timeout is reset to 30 min on each print job).

cmd_schedule_switch_off(){
  # Cancel any scheduled turn-off
  # Browse all AT tasks and, for those containing the script name ($0), ask AT to stop them
  for j in $(atq | cut -f 1);
  do
    if at -c $j | grep -q $0; then
		echo Stop scheduled turn-off task $j
		at -r $j
	fi
  done
  
  # Schedule in 30 minutes to turn off the plug
  echo "$0 $ip $port off" | at now+30minute
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions