-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_assistant.lua
50 lines (44 loc) · 1.54 KB
/
home_assistant.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local env = require("env")
--alex's bedroom
function toggleAlexBedroom()
local url = env.HASS_URL .. "/api/services/light/toggle"
local headers = {
["Authorization"] = "Bearer " .. env.HASS_TOKEN,
["Content-Type"] = "application/json"
}
local body = '{"entity_id": "light.alexs_bedroom"}'
hs.http.post(url, body, headers)
end
function dimAlexBedroom()
local url = env.HASS_URL .. "/api/services/light/turn_on"
local headers = {
["Authorization"] = "Bearer " .. env.HASS_TOKEN,
["Content-Type"] = "application/json"
}
local body = '{"entity_id": "light.alexs_bedroom", "brightness_step": -40}'
hs.http.post(url, body, headers)
end
function brightenAlexBedroom()
local url = env.HASS_URL .. "/api/services/light/turn_on"
local headers = {
["Authorization"] = "Bearer " .. env.HASS_TOKEN,
["Content-Type"] = "application/json"
}
local body = '{"entity_id": "light.alexs_bedroom", "brightness_step": 40}'
hs.http.post(url, body, headers)
end
--alex's desk lamp
function toggleAlexDeskLamp()
local url = env.HASS_URL .. "/api/services/light/toggle"
local headers = {
["Authorization"] = "Bearer " .. env.HASS_TOKEN,
["Content-Type"] = "application/json"
}
local body = '{"entity_id": "light.alexs_desk_lamp"}'
hs.http.post(url, body, headers)
end
--keybindings
hs.hotkey.bind({"cmd", "ctrl"}, "1", toggleAlexBedroom)
hs.hotkey.bind({"cmd", "ctrl"}, "-", dimAlexBedroom)
hs.hotkey.bind({"cmd", "ctrl"}, "=", brightenAlexBedroom)
hs.hotkey.bind({"cmd", "ctrl"}, "2", toggleAlexDeskLamp)