Page 1 of 1
mqtt or json
Posted: Tuesday 11 June 2019 20:54
by pvklink
Would be great if you can activate (json, post message body) a switch based on the switch name, or levelname instead of the idx
{"command": "switchlight", "name": "lamp_x", "switchcmd": "Off"}
also tried
http://192.168.20.35:82/json.htm?type=d ... e=lantaarn to read the IDX in NODE-red
In google home you can give the command: turn lamp_x or lamp_y on or off
Using a IDX in natural languages does not make sense...
In IFTTT you only have to write two scripts ON or OFF and use a variable for the device_name...
My (working) configuation:
Google home (RPI 3b+) --> IFTTT --> NODE-RED --> MQTT --> domoticz....
I tried to let NODE-RED do the conversion name --> id, but i did not get it working....
I have generic POST and GET's working on my NODE-red with MQTT and domoticz
Re: mqtt or json
Posted: Wednesday 12 June 2019 11:49
by waaren
pvklink wrote: ↑Tuesday 11 June 2019 20:54
Would be great if you can activate (json, post message body) a switch based on the switch name, or levelname instead of the idx
In google home you can give the command: turn lamp_x or lamp_y on or off
Using a IDX in natural languages does not make sense...
In IFTTT you only have to write two scripts ON or OFF and use a variable for the device_name...
My (working) configuation: Google home (RPI 3b+) --> IFTTT --> NODE-RED --> MQTT --> domoticz....
Would it help if you could change this to ?
Google home (RPI 3b+) --> IFTTT --> domoticz user variable (control var) --> dzVents script --> domoticz device
Re: mqtt or json
Posted: Wednesday 12 June 2019 12:19
by pvklink

- Naamloos.png (44.09 KiB) Viewed 1930 times
I almost have it working with GA, IFTT, NODE-red, MQTT, domoticz
In IFTT you can ask for the "name" and ON/OFF so you only need one IFTT script !
i made three flows,
1. one for post's with IDX --> already working!
2. one for get's with IDX --> already working!
Under construction
3. one for post's with device name,
- {"command":"switchlight","name":"lantaarn","switchcmd":"On"}
- then i do a
http://xxxxxx/json.htm?type=command&par ... htswitches
- then search for the "name", change the message, use idx instead of name and then the normal POST flow....
i hope and think this is going to work!
When they all work i will combine them and then you have a sort off API between IFTTT and MQTT via node-red for POSTS, GETS, idx or names
Re: mqtt or json
Posted: Wednesday 12 June 2019 12:33
by pvklink
thougt about your CONTROLVAR solution...
That is GREAT!
Does it contains something like "Lantaarn ON"
And then a default DZVENTS script to interpretate and execute it?
I can also combine this with node-red
/json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE
i make a default message for this and ASK within IFTT for name
{"command": "updateuservariable","vname":"ifttvar","vtype":"String","vvalue":" {{TextField}}"}
then the uservar is filled.. i think
Re: mqtt or json
Posted: Wednesday 12 June 2019 13:24
by pvklink
I got the first part working from ifttt and nodered/mqttt
http://192.168.20.35:82/json.htm?type=c ... 2&vvalue=a
domoticz mqttt does not execute the change in the uservar
This is the payload to mqttt
12-6-2019 14:10:47node: d0f0155b.51fc88
msg.payload : string[77]
"{"command":"updateuservariable","vname":"iftttvar","vtype":2,"vvalue":"lamp"}"
strange, this works with switches etc....
@update found it!
https://www.domoticz.com/wiki/MQTT
{"command":"setuservariable","idx":12,"value":"lamp"}
Re: mqtt or json
Posted: Wednesday 12 June 2019 16:07
by pvklink
I can manage the uservar IFTTTVAR now by speech. it gets the value LAMP X ON or LAMP x OFF
so i have Google home --> IFTTT --> NODE-RED --> MQTT --> domoticz uservar IFTTTVAR
Re: mqtt or json
Posted: Sunday 16 June 2019 19:28
by hansake
It would indeed be very nice if I can use the device name instead of the device IDX when sending
measurements from a sensor using MQTT.
I have a NodeMCU/ESP8266 based sensor node with a 1-Wire interface. This sensor node is sending
temperature measurements to Domoticz using MQTT. The device IDX has to be hardcoded in the
NodeMCU sketch and this is not optimal I think.
The sketch code is here:
https://github.com/hansake/Domoticz_NodeMCU_MQTT
The device IDX could be determined by sending a query to Domoticz using MQTT but this would
complicate the code in the NodeMCU.
Regards
Hans-Åke
Re: mqtt or json
Posted: Saturday 29 June 2019 11:57
by pvklink
i migrated all my iftt applets to use the @waaren ifttt solution, works great.
i tried to adjust it a little bit so that i can use it also for selecting selector switches with an selector id instead off selector name..
so parm1 for example could be Radio or 20
i need a check to check if parm1 is a string or a number .
if it is a number the action =
target.switchSelector(tonumber(parm1)) --parm selector_id
if it is a number then
target.switchSelector(parm1) --parm selector_name
Code: Select all
local iftttvar = "iftttvar"
return
{
on =
{ variables = { iftttvar },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'ifttt',
},
execute = function(dz, item)
local validBaseTypes = { device=true, group=true, scene=true, uservariable=false, camera=false }
local validActions = { ON=true, OFF=true }
result = dz.utils.stringSplit(item.value,'/')
local name = result[1]
local action = string.upper(result[2])
local parm1 = result[3]
local function getBaseType(name)
for i, tuple in ipairs(_G.domoticzData) do
if tuple.name == name then
return tuple.baseType, tuple.id
end
end
end
local baseType, idx = getBaseType(name)
if baseType and validBaseTypes[baseType] then
local target
if baseType == 'device' then
target = dz.devices(name)
elseif baseType == 'group' then
target = dz.groups(name)
elseif baseType == 'scene' then
target = dz.scenes(name)
validActions.OFF = nil -- No Off action for scenes
end
if validActions[action] then
if action == 'ON' then
if parm1 then
--2019-06-29 11:46:37.971 Error: dzVents: Error: (2.4.23) ifttt: xxx IFTTT target:denon_volumeparm1:30/ en waarde van uservar:denon_volume/On/30
--2019-06-29 11:46:37.971 Error: dzVents: Error: (2.4.23) ifttt: levelname 30 does not exist
dz.log('xxx IFTTT target:' .. tostring(target.name) .. 'parm1:' .. parm1 .. '/ en waarde van uservar:' .. item.value,dz.LOG_ERROR)
target.switchSelector(parm1) --parm selector_name
--target.switchSelector(tonumber(parm1)) --parm selector_id
else
target.switchOn()
end
elseif action == 'OFF' then target.switchOff()
else -- no other actions implemented yet
end
else
dz.log('action ' .. action .. ' is not implemented for ' .. baseType .. ' ' .. name .. '!',dz.LOG_ERROR)
end
elseif baseType then
dz.log(name .. " is a " .. baseType .. " don't know what to do with that!",dz.LOG_ERROR)
else
dz.log(name .. " Not found!",dz.LOG_ERROR)
end
end
}