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.
Blynk to Domoticz [Solved]
Moderator: leecollings
Re: Blynk to Domoticz
Hi,
You can try to do with Lua script:
Script not tested, I took sample from my Domoticz script's from Github.
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 } )
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Blynk to Domoticz
Can you try this ?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.
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Blynk to Domoticz
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 2
- Joined: Thursday 13 February 2020 9:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Blynk to Domoticz [Solved]
it works, thanks Waaren !!!
Who is online
Users browsing this forum: No registered users and 1 guest