Blynk to Domoticz  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
dirkr
Posts: 2
Joined: Thursday 13 February 2020 9:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Blynk to Domoticz

Post 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.
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Blynk to Domoticz

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blynk to Domoticz

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blynk to Domoticz

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dirkr
Posts: 2
Joined: Thursday 13 February 2020 9:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blynk to Domoticz  [Solved]

Post by dirkr »

it works, thanks Waaren !!!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest