Splitting multiple values in one device to multiple single devices

Moderator: leecollings

Post Reply
S10NL
Posts: 12
Joined: Sunday 23 February 2020 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Splitting multiple values in one device to multiple single devices

Post by S10NL »

Hi All,

I'm trying to realize split values from a multiple value device buienradar script.
Let me state that i am in no way a programmer but i somewhat understand the logic behind programming.
And so i try to combine and rebuild existing scripts to realize my goal.

I have this lua script running which grabs only the currect temperature from the weather underground device and puts it in a virtual device. So i can use this value in blockly scripts.
This splitting of values is the goal im trying to accomplish but now for a different source, namely Buienradar.
I want the wind and windgust values in two different devices.

situation:
Source device states the following values: 228.0;SW;99;141;8.3;4.0
I want to grab the third and fourth value.

I've created the script below for the third value, but its not working as expected:
Please ignore all the uncommented rows

Code: Select all

--Script To Parse WeatherUnderground Multi-Value Sensor, Additionally using PWS: system from WU with a new output format
--This script assumes the output (which can be viewed in events show current state button) is like this 19.5;79;3;1019;3 (temp;humidity;null;pressure;null)
--more details at this wiki http://www.domoticz.com/wiki/Virtual_weather_devices
--
--The following need updated for your environment get the 'Idx' or 'Name' off the Device tab. By default only the Temp is 'uncommented or enabled' in this script.
local sensorwu = 'Buienradar - Wind' --name of the sensor that gets created when you add the WU device (and that contains multiple values like temperature, humidity, barometer etc)
local idxt = 79 --idx of the virtual temperature sensor you need to change this to your own Device IDx
--local idxh = 999 --idx of the virtual humidity sensor you need to change this to your own Device IDx
--local idxp = 999 --idx of the virtual pressure sensor you need to change this to your own Device IDx

commandArray = {}

if devicechanged[sensorwu] then
        sWindrichtingNUM, sWindrichting, sWind, sWindhoos, sA = otherdevices_svalues[sensorwu]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
        --sWindrichtingNUM = tonumber(sWindrichtingNUM)
        --sWindrichting = tonumber(sWindrichting)
        sWind = tonumber(sWind)
        --sWindhoos = tonumber(sWindhoos)
        --parseDebug = ('WU Script Parsed Temp=' .. sWindrichtingNUM .. ' Humidity=' .. sWindrichting .. ' Pressure=' .. sWindhoos)
        --print(parseDebug)

        commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. sWind}
        --commandArray[2] = {['UpdateDevice'] = idxh .. '|' .. tostring(sWindrichting) .. '|' .. tostring(sWind)}
        --commandArray[3] = {['UpdateDevice'] = idxp .. '|0|' .. tostring(sWindhoos) .. ';' .. tostring(sWeatherPressForcast)}
end
 
return commandArray
This script works partially because it returns two values namely: 0, 99 in the devices screen.
The weather tab shows an empty device.

What should i do to make this script work the way i want it to?
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Splitting multiple values in one device to multiple single devices

Post by bewo »

Hi S10NL,

are you get it working? If not, your goal is possible to reach but a bit more information is necessary.
And maybe there could be an issue. The "normal wind device" which you could select in domoticz saves both values wind and windgust.

So my question is: What would you like to do? What's the job of the blocky you would like to generate?

Close an sunblind or somthing? Just do it directly in LUA. We'll help you. ;-)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
S10NL
Posts: 12
Joined: Sunday 23 February 2020 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Splitting multiple values in one device to multiple single devices

Post by S10NL »

Thanks for your reply!

Eventually there was nothing wrong with my script, but the device i wanted to put the results in expected multiple values ( it was a wind device).
When i changed the device to a generic device, all was working without a problem.

I just didnt know that a specific device type consisted of defined format of x values, and all these values need to be passed on. Without the specified values, the device will give this error => Reveived 2 values expected 5 values.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest