Page 1 of 1
Set value of virtual device with alphanumerical idx
Posted: Friday 19 August 2016 10:50
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.
Re: Set value of virtual device with alphanumerical idx
Posted: Friday 19 August 2016 11:04
by trixwood
You probably missing some quotes, or forgot to convert a type. Post your code, so we can look at it.
Re: Set value of virtual device with alphanumerical idx
Posted: Tuesday 23 August 2016 15:11
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¶m=udevice&idx='..tostring(idxt)..'&nvalue=0&svalue='..tostring(sWeatherTemp)
-- commandArray['OpenURL'] = myjson
-- print('json= ' .. myjson)
-- commandArray['WUTemp']=sWeatherTemp
--end
return commandArray
Re: Set value of virtual device with alphanumerical idx
Posted: Wednesday 09 November 2016 9:33
by pdjm43
here you go.
Code: Select all
i=0
help="big boy"
idx="173"
i=i+1
commandArray[i]={['UpdateDevice']=idx..'|0|'..help}
Re: Set value of virtual device with alphanumerical idx
Posted: Wednesday 09 November 2016 20:04
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.
Re: Set value of virtual device with alphanumerical idx
Posted: Wednesday 09 November 2016 20:13
by jvdz
@Sergio, Are you sure that is the IDX and not the ID you refer to?
Jos
Re: Set value of virtual device with alphanumerical idx
Posted: Wednesday 09 November 2016 20:29
by Sergio
Look, you're absolutely right. I confused the Id with idx.

- Sin título.png (12.85 KiB) Viewed 2686 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?