Page 1 of 1
Hue formula with openURL [Solved]
Posted: Thursday 04 June 2020 11:26
by johnnyboy1984
Hi there,
I am trying to switch a formula (tv mimicking) on/off with a dummy switch.
I want when the dummy switch is switched on/off to start or stop the hue tv mimicking formula. Unfortunatly it doesn't work. I retrieved the api and code with the HUE clip api debugger and that works, but i don't know how to convert the code into a script, please help:
Code: Select all
return {
on = {
devices = {
'test1'
}
},
execute = function(domoticz, switch)
if (switch.state == 'On') then
domoticz.log('TV Mimick on')
domoticz.openURL({
url = 'http://<my hue ipadress>/api/<my api code>/sensors/55/state',
method = 'PUT',
put = { "status": 1 }
})
else
domoticz.log('TV Mimick off!')
domoticz.openURL({
url = 'http://<my hue ipadress>/api/<my api code>/sensors/55/state',
method = 'PUT',
put = { "status": 0 }
})
end
end
}
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 11:47
by waaren
johnnyboy1984 wrote: Thursday 04 June 2020 11:26
I retrieved the api and code with the HUE clip api debugger and that works, but i don't know how to convert the code into a script, please help:
From the wiki:
postData: Optional. When doing a POST, PUT 3.0.2 or DELETE 3.0.2 this data will be the payload of the request (body).
so try with:
Code: Select all
return {
on = {
devices = {
'test1'
}
},
execute = function(domoticz, switch)
if (switch.state == 'On') then
domoticz.log('TV Mimick on')
domoticz.openURL({
url = 'http://<my hue ipadress>/api/<my api code>/sensors/55/state',
method = 'PUT',
postData = { "status" = 1 }
})
else
domoticz.log('TV Mimick off!')
domoticz.openURL({
url = 'http://<my hue ipadress>/api/<my api code>/sensors/55/state',
method = 'PUT',
postData = { "status" = 0 }
})
end
end
}
If it still fails, please share the relevant loglines and the version you are on.
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 11:58
by johnnyboy1984
still no succes, error log sais:
Code: Select all
2020-06-04 11:55:26.006 Error: dzVents: Error: (3.0.1) error loading module 'Script Hue TV mimicking' from file '/usr/local/domoticz/var/scripts/dzVents/generated_scripts/Script Hue TV mimicking.lua':
2020-06-04 11:55:26.006 ...ts/dzVents/generated_scripts/Script Hue TV mimicking.lua:14: '}' expected near ':'
i have dzVents Version: 3.0.1
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 12:19
by waaren
johnnyboy1984 wrote: Thursday 04 June 2020 11:58
Still no succes
i have dzVents Version: 3.0.1
The methods PUT and DELETE are not available in dzVents version 3.0.1
These methods were introduced in Version 3.0.2
Also change "status" : 1 to "status" = 1
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 12:25
by johnnyboy1984
ok, and dzVents 3.0.2 is in Domoticz 2020.2 right?
But that vesrsion is not available for Synology, is there another way with Lua maybe to achivef my goals?
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 12:29
by waaren
johnnyboy1984 wrote: Thursday 04 June 2020 12:25
ok, and dzVents 3.0.2 is in Domoticz 2020.2 right?
But that version is not available for Synology, is there another way with Lua maybe to achieve my goals?
Not natively with dzVents or Lua but os.execute(CurlCommand) in a dzVents script could be a work around.
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 13:54
by johnnyboy1984
ok, so i found this other
https://www.domoticz.com/forum/viewtopi ... 36&t=31481, and used a part of the script, but still an error in my log:
Code: Select all
return {
on = {
devices = {
'test1'
}
},
execute = function(domoticz, switch)
if (switch.state == 'On') then
domoticz.log('TV Mimick on')
os.execute('curl --header "Content-Type: application/json" --request PUT --data '{"status":1}' http://<my hue ipadress>/api/<my api code>/sensors/55/state')
else
domoticz.log('TV Mimick off!')
os.execute('curl --header "Content-Type: application/json" --request PUT --data '{"status":0}' http://<my hue ipadress>/api/<my api code>/sensors/55/state')
end
end
}
log:
Code: Select all
2020-06-04 13:52:58.977 Error: dzVents: Error: (3.0.1) error loading module 'Script Hue TV mimicking 2' from file '/usr/local/domoticz/var/scripts/dzVents/generated_scripts/Script Hue TV mimicking 2.lua':
2020-06-04 13:52:58.977 .../dzVents/generated_scripts/Script Hue TV mimicking 2.lua:11: ')' expected near '{'
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 14:25
by waaren
johnnyboy1984 wrote: Thursday 04 June 2020 13:54
ok, so i found this other
https://www.domoticz.com/forum/viewtopi ... 36&t=31481, and used a part of the script, but still an error in my log:
Code: Select all
2020-06-04 13:52:58.977 Error: dzVents: Error: (3.0.1) error loading module 'Script Hue TV mimicking 2' from file '/usr/local/domoticz/var/scripts/dzVents/generated_scripts/Script Hue TV mimicking 2.lua':
2020-06-04 13:52:58.977 .../dzVents/generated_scripts/Script Hue TV mimicking 2.lua:11: ')' expected near '{'
some quote problems..
Can you try:
Code: Select all
return
{
on =
{
devices =
{
'test1',
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Curl to hue' ,
},
execute = function(dz, switch)
dz.log('TV Mimick ' .. switch.state, dz.LOG_DEBUG)
local hueCommand = ( switch.state == 'On' and 1 ) or 0
local curlCommand = 'curl --header "Content-Type: application/json" --request PUT --data \'{"status": ' .. hueCommand .. ' }\' http://<Hue IP>/api/<API CODE>/sensors/55/state'
os.execute(curlCommand)
dz.log('curl Commnand: ' .. curlCommand, dz.LOG_DEBUG)
end
}
If it does not work yet just copy the command you see in the log and try it from the CLI.
curl will show you what's wrong.
Re: Hue formula with openURL
Posted: Thursday 04 June 2020 14:42
by johnnyboy1984
This works!!! Thanks a lot.
I removed the extra loggin now and can use it.
Code: Select all
return
{
on =
{
devices =
{
'test1',
}
},
execute = function(dz, switch)
local hueCommand = ( switch.state == 'On' and 1 ) or 0
local curlCommand = 'curl --header "Content-Type: application/json" --request PUT --data \'{"status": ' .. hueCommand .. ' }\' http://<my hue ipadress>/api/<my api code>/sensors/55/state'
os.execute(curlCommand)
end
}