04.12.2022, 13:06
Home Assistant support Apple TV standby, so i used that product also.
So make a script in Home Assistant and run that script with the LM
So make a script in Home Assistant and run that script with the LM
Code:
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
token = "xxxxxxxxxxxxxx" --generate long use token in HA (10 years lifetime)
function runScript(iDevice, iScript, iScriptId)
data = json.encode({
query = '{"entity_id": "'..iScriptId..'"}'
})
tbl = {}
res, code = https.request({
url = 'http://'..iDevice..'/api/services/script/'..iScript,
method = 'POST',
headers = {
['authorization'] = 'Bearer ' .. token,
['content-type'] = 'application/json',
['content-length'] = #data,
},
source = ltn12.source.string(data),
sink = ltn12.sink.table(tbl),
})
--[[
if res and code == 200 then
resp = table.concat(tbl)
resp = json.pdecode(resp)
log(resp)
else
log(res, code)
end
--]]
end
-- standby apple tv woonkamer (ip, scriptname, scriptid)
--runScript("192.168.X.XX:8123", "AppleTVWoonkamer_Standby", "script.appletvwoonkamer_standby")