14.04.2022, 18:36
Hi,
funny thing I just started working on the same topic today. :-)
I got it working for the motion state:
1.) Add the following code to the hue user library script:
2.) Implement a resident script (example for motion):
If you want to have the temperature just looking for the name inside the json e.g. = Hue outdoors temp. sensor 1" and change: "item.state.presence" to "item.state.temperature". This is working I tested it. Due to I just want to have the motion state I didn't implemented it.
To get the json "readable" I used: https://jsonformatter.org/json-parser
I hope this is helping you.
Best Regards
Steffen
funny thing I just started working on the same topic today. :-)
I got it working for the motion state:
1.) Add the following code to the hue user library script:
Code:
-- function get data from sensors
function getHueSensors()
local response = {}
body_searchHueSensors= ''
-- Set username for LogicMachine
socket.http.request({
url = "http://"..ip_add.."/api/"..user.."/sensors",
method = 'GET',
sink = ltn12.sink.table(response),
headers = {
['content-length'] = #body_searchHueSensors,
['content-type'] = 'application/json',
},
source = ltn12.source.string(body_searchHueSensors),
})
return response
end
2.) Implement a resident script (example for motion):
Code:
addressmapping = {
-- Name -- Presence FB
['Hue motion 1'] = {state = '47/2/6', statevalue = ''},
}
-- Use logging
logging = true
require('user.hue')
require('json')
reply = getHueSensors()
mysensors = json.pdecode(reply[1])
for _, item in pairs(mysensors) do
-- Check if sensor is found by bridge otherwise it make no sense to send commands
if item.config.reachable == true then
-- On/Off
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['state']
if addr and addr ~= '' then
currentvalue = addressmapping[item.name]['statevalue']
if currentvalue ~= item.state.presence then
grp.update(addr, item.state.presence)
addressmapping[item.name]['statevalue'] = item.state.presence
if logging == true then
log('sensor ' .. item.name .. ' state is: ' .. tostring(item.state.presence))
end
end
end
end
end
end
If you want to have the temperature just looking for the name inside the json e.g. = Hue outdoors temp. sensor 1" and change: "item.state.presence" to "item.state.temperature". This is working I tested it. Due to I just want to have the motion state I didn't implemented it.
To get the json "readable" I used: https://jsonformatter.org/json-parser
I hope this is helping you.
Best Regards
Steffen