Set value of virtual device with alphanumerical idx

Moderator: leecollings

Post Reply
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Set value of virtual device with alphanumerical idx

Post by Sergio »

Creating a new virtual device seems to always assing an alphanumeric id. I'm trying to give this device a value on a lua script without success.
Update device always expects an integer idx and doesn't set my virtual temperature device.
And a commandArray assign throws error as well: Error: EventSystem: commandArray in script script_time_SetTemp should only return ['string']='actionstring' or [integer]={['string']='actionstring'}

Does anyone knows how to make this?
Thanks.
trixwood

Re: Set value of virtual device with alphanumerical idx

Post by trixwood »

You probably missing some quotes, or forgot to convert a type. Post your code, so we can look at it.
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Set value of virtual device with alphanumerical idx

Post by Sergio »

trixwood wrote:You probably missing some quotes, or forgot to convert a type. Post your code, so we can look at it.
Thank you trixwood and sorry, I've been busy from stomach illness.
I'm using the script for getting temperature from THB sensor at the wiki. I've been trying some things so the script is messed.

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 = 'WUTHB' --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 = '140BD' --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
        sWeatherTemp, sWeatherHumidity, sHumFeelsLike, sWeatherPressure = otherdevices_svalues[sensorwu]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
        sWeatherTemp = tonumber(sWeatherTemp)
        sWeatherHumidity = tonumber(sWeatherHumidity)
        sWeatherPressure = tonumber(sWeatherPressure)
        print('WU Script Parsed Temp=' .. sWeatherTemp .. ' Humidity=' .. sWeatherHumidity .. ' Pressure=' .. sWeatherPressure)
 
        commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. tostring(sWeatherTemp)}
--        commandArray[1] = {['UpdateDevice'] = tostring(idxt) .. '|0|' .. tostring(sWeatherTemp)}
        --commandArray[2] = {['UpdateDevice'] = idxh .. '|' .. tostring(sWeatherHumidity) .. '|' .. tostring(sHumFeelsLike)}
        --commandArray[3] = {['UpdateDevice'] = idxp .. '|0|' .. tostring(sWeatherPressure) .. ';' .. tostring(sWeatherPressForcast)}
--        myjson = 'http://192.168.11.245/json.htm?type=command&param=udevice&idx='..tostring(idxt)..'&nvalue=0&svalue='..tostring(sWeatherTemp)
--        commandArray['OpenURL'] = myjson
--        print('json= ' .. myjson)
--        commandArray['WUTemp']=sWeatherTemp
--end
 
return commandArray
pdjm43
Posts: 30
Joined: Friday 12 December 2014 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: UK
Contact:

Re: Set value of virtual device with alphanumerical idx

Post by pdjm43 »

here you go.

Code: Select all

i=0
help="big boy"
idx="173"
i=i+1
commandArray[i]={['UpdateDevice']=idx..'|0|'..help}
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Set value of virtual device with alphanumerical idx

Post by Sergio »

pdjm43 wrote:here you go.
...
Thanks pdjm43, but note the problem here is that the destination idx is alphanumerical. Aka "140BD" in my system.
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Set value of virtual device with alphanumerical idx

Post by jvdz »

@Sergio, Are you sure that is the IDX and not the ID you refer to?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Set value of virtual device with alphanumerical idx

Post by Sergio »

Look, you're absolutely right. I confused the Id with idx. :o :oops:
Sin título.png
Sin título.png (12.85 KiB) Viewed 2654 times
Now it works! Well... I feel stupid.

But now, I see that I have two devices with same id. Should that be why I couldn't work with "IsDark" on blocky lately. :?:
It's normal?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest