From c6535a201ba4df4fe2cd1ff430aea13e69c0741d Mon Sep 17 00:00:00 2001 From: Dan Wetherald Date: Thu, 10 Dec 2020 16:18:20 -0600 Subject: [PATCH] office monitor day and night scenes --- hammerspoon/brightness.lua | 6 +++--- hammerspoon/monitors.lua | 12 ++++++++---- hammerspoon/status.lua | 27 --------------------------- 3 files changed, 11 insertions(+), 34 deletions(-) delete mode 100644 hammerspoon/status.lua diff --git a/hammerspoon/brightness.lua b/hammerspoon/brightness.lua index d0072bd..6473abc 100644 --- a/hammerspoon/brightness.lua +++ b/hammerspoon/brightness.lua @@ -3,12 +3,12 @@ appWatcher = nil function appChanged(appName, eventType, appObject) hour = tonumber(os.date("%H")) - if hour > 18 or hour < 7 then + if hour > 21 or hour < 7 then if (eventType == hs.application.watcher.activated) then if (appName == "kitty") then - -- hs.brightness.set(30) + hs.brightness.set(30) else - -- hs.brightness.set(1) + hs.brightness.set(1) end end end diff --git a/hammerspoon/monitors.lua b/hammerspoon/monitors.lua index 76cee07..69f4593 100644 --- a/hammerspoon/monitors.lua +++ b/hammerspoon/monitors.lua @@ -7,7 +7,8 @@ local headers = { ["Content-Type"] = "application/json" } -local payload = [[ {"entity_id":"scene.officenightwork"} ]] +local day_payload = [[ {"entity_id":"scene.officedaywork"} ]] +local night_payload = [[ {"entity_id":"scene.officenightwork"} ]] screenWatcher = nil @@ -18,9 +19,12 @@ function screenChanged(watcher) -- Checkout that its night hour = tonumber(os.date("%H")) - if hour >= 18 or hour < 7 then - -- Turn on Home Assistant Scene - hs.http.post(path, payload, headers) + + -- Turn on Home Assistant Scene + if hour >= 16 or hour < 7 then + hs.http.post(path, night_payload, headers) + else + hs.http.post(path, day_payload, headers) end end end diff --git a/hammerspoon/status.lua b/hammerspoon/status.lua deleted file mode 100644 index 80039f6..0000000 --- a/hammerspoon/status.lua +++ /dev/null @@ -1,27 +0,0 @@ -local path = "http://192.168.1.103:8123/api/services/scene/turn_on" - -local token = "" - -local headers = { - ["Authorization"] = "Bearer " .. token, - ["Content-Type"] = "application/json" -} - -local payload = [[ {"entity_id":"scene.officenightwork"} ]] - -sessionWatcher = nil - -function sessionChanged(eventType) - hour = tonumber(os.date("%H")) - - -- After 6pm before 7am - if hour > 18 or hour < 7 then - if (eventType == hs.caffeinate.watcher.screensDidUnlock) then - hs.http.post(path, payload, headers) - end - end - -end - -sessionWatcher = hs.caffeinate.watcher.new(sessionChanged) -sessionWatcher:start()