Page 1 of 1
Blynk to Domoticz
Posted: Thursday 13 February 2020 9:12
by dirkr
I have been using Blynk for a long time to read out my sensors and display the values on my cell phone. I am quite satisfied with that and want to continue using this. I would also like to have read the results in Domoticz. The answer to the Http requst "
http://blynk-cloud.com/***MyAuthToken***/get/V10" (V10 is a temperature sensor) looks like this: ["27,000"].
This does not seem to me to be a Json format. How can I send this result (27 ° C) to Domoticz?
Thanks for your help.
Re: Blynk to Domoticz
Posted: Thursday 13 February 2020 9:45
by zygios
Hi,
You can try to do with Lua script:
Code: Select all
commandArray = {}
local dom_idx = 10 //device idx in domoticz
local API_URL = 'http://blynk-cloud.com/***MyAuthToken***/get/V10'
local config=assert(io.popen('curl "'..API_URL..'"'))
local RAWdata = config:read('*all')
print(RAWdata)
config:close()
local updatetext = string.format("%d|0|%.2f", dom_idx, RAWdata)
print("updatetext:" .. updatetext)
table.insert (commandArray, { ['UpdateDevice'] = updatetext } )
Script not tested, I took sample from my Domoticz script's from Github.
Re: Blynk to Domoticz
Posted: Thursday 13 February 2020 10:41
by waaren
dirkr wrote: ↑Thursday 13 February 2020 9:12
I have been using Blynk for a long time to read out my sensors and display the values on my cell phone. I am quite satisfied with that and want to continue using this. I would also like to have read the results in Domoticz. The answer to the Http requst "
http://blynk-cloud.com/***MyAuthToken***/get/V10" (V10 is a temperature sensor) looks like this: ["27,000"].
This does not seem to me to be a Json format. How can I send this result (27 ° C) to Domoticz?
Thanks for your help.
Can you try this ?
Code: Select all
local scriptVar = 'getBlynkData'
return
{
on =
{
timer =
{
'every minute' -- just an example to trigger the request
},
httpResponses =
{
scriptVar,
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- change DEBUG to ERROR when script executes as expected
marker = scriptVar,
},
execute = function(dz, item)
-------------- local settings below this line
local blynkSensor = dz.devices('blynkSensor') -- change to name of your domoticz temperature sensor
local blynkURL = 'http://blynk-cloud.com/***MyAuthToken***/get/V10'
local numDecimals = 1
-------------- no changes required below this line
-- helper function to convert string representing float with , as decimal point
-- returns float if value can be converted to number and value otherwise
local function string2Number( value )
if type(value) ~= 'string' then
return value
else
local str = value:gsub(',','.')
return tonumber(str) or value
end
end
if not(item.isHTTPResponse) then
dz.openURL(
{
url = blynkURL,
method = 'GET',
callback = scriptVar, -- see httpResponses above.
})
elseif item.ok then -- statusCode == 2xx
dz.log('value from blynk: ' .. item.data,dz.LOG_DEBUG)
blynkSensor.updateTemperature( dz.utils.round( string2Number( dz.utils.fromJSON(item.data)[1]), numDecimals))
else
dz.log('There was a problem handling the request', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
Re: Blynk to Domoticz
Posted: Thursday 13 February 2020 10:51
by waaren
zygios wrote: ↑Thursday 13 February 2020 9:45
You can try to do with Lua script:
Script not tested, I took sample from my Domoticz script's from Github.
Sorry but this will not work.
- RAWdata is a string and the string.format expects a number
- RAWdata uses a comma as decimal seperator and Lua expects a decimal point
- the io.popen function will block the entire event system when blynk-cloud cannot be reached for any reason
Re: Blynk to Domoticz [Solved]
Posted: Thursday 13 February 2020 22:00
by dirkr
it works, thanks Waaren !!!