Get temp only from Weather Underground Topic is solved

Post Reply
Extremo
Posts: 7
Joined: Monday 02 April 2018 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Switzerland
Contact:

Get temp only from Weather Underground

Post by Extremo » Monday 02 April 2018 12:56

Hi all

Just fighting a bit with Domoticz and Weather Underground. Was able to setup WU properly according to wiki, now I wanted to grab only the temperature, because I need temp only for some scripts. So I setup the script described also in wiki (https://www.domoticz.com/wiki/Virtual_w ... emperature), but I don't get it working. Have changed the first both vars of the script according to my setup and uncommented the debug part:

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 = 'WU-THB' --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 = 124 --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)
        parseDebug = ('WU Script Parsed Temp=' .. sWeatherTemp .. ' Humidity=' .. sWeatherHumidity .. ' Pressure=' .. sWeatherPressure)
        print(parseDebug)

        commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. sWeatherTemp}
        --commandArray[2] = {['UpdateDevice'] = idxh .. '|' .. tostring(sWeatherHumidity) .. '|' .. tostring(sHumFeelsLike)}
        --commandArray[3] = {['UpdateDevice'] = idxp .. '|0|' .. tostring(sWeatherPressure) .. ';' .. tostring(sWeatherPressForcast)}
end

return commandArray
Here my device values:
Image
Image

The Script is placed under ~/domoticz/scripts/lua/script_device_wu.lua, based on the logs, it seems that the script will not be triggered:

Code: Select all

2018-04-02 12:45:37.234 (Weather Underground) Temp + Humidity + Baro (WU-THB)
2018-04-02 12:45:37.236 (Weather Underground) Wind (Unknown)
2018-04-02 12:45:37.238 (Weather Underground) UV (UV)
2018-04-02 12:45:37.241 (Weather Underground) Rain (Unknown)
2018-04-02 12:45:37.243 (Weather Underground) General/Solar Radiation (Unknown)
2018-04-02 12:55:37.724 (Weather Underground) Temp + Humidity + Baro (WU-THB)
2018-04-02 12:55:37.726 (Weather Underground) Wind (Unknown)
2018-04-02 12:55:37.728 (Weather Underground) UV (UV)
2018-04-02 12:55:37.730 (Weather Underground) Rain (Unknown)
2018-04-02 12:55:37.732 (Weather Underground) General/Solar Radiation (Unknown)
Does anyone was able to get this script running or maybe see a failure in my script? Thanks for your help!

User avatar
jvdz
Posts: 1463
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Get temp only from Weather Underground

Post by jvdz » Monday 02 April 2018 13:16

This works fine for me with the same setup (different devicename) and both if's are true when there is an update:

Code: Select all

if devicechanged[sensorwu..'_Temperature'] then
   print(sensorwu..'_Temperature')
   print(otherdevices_svalues[sensorwu])
   print(otherdevices_temperature[sensorwu])
end
if devicechanged[sensorwu] then
   print(sensorwu)
   print(otherdevices_svalues[sensorwu])
   print(otherdevices_temperature[sensorwu])
end
As you can see, it is pretty easy to get just the temperature part without any regex.

Jos

Extremo
Posts: 7
Joined: Monday 02 April 2018 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Switzerland
Contact:

Re: Get temp only from Weather Underground

Post by Extremo » Monday 02 April 2018 14:03

Hi Jos

Thanks for your fast answer. I created, based on your script, a own version (~/domoticz/scripts/lua/script_device_wu.lua):

Code: Select all

commandArray={}

sensorwu = 'WU-THB'

print('Debug Note')

if devicechanged[sensorwu..'_Temperature'] then
   print(sensorwu..'_Temperature')
   print(otherdevices_svalues[sensorwu])
   print(otherdevices_temperature[sensorwu])
end

return commandArray
But the script will not be triggered on Weather Underground Event (every 10 Minutes):

Code: Select all

2018-04-02 13:57:40.682 (Weather Underground) Temp + Humidity + Baro (WU-THB)
2018-04-02 13:57:40.684 (Weather Underground) Wind (Unknown)
2018-04-02 13:57:40.686 (Weather Underground) UV (UV)
2018-04-02 13:57:40.688 (Weather Underground) Rain (Unknown)
2018-04-02 13:57:40.689 (Weather Underground) General/Solar Radiation (Unknown)
But it will be triggered, when I run another sensor on my system:

Code: Select all

2018-04-02 13:58:30.042 User: Admin initiated a switch command (30/Garten Pool/On)
2018-04-02 13:58:30.043 RFLink Sending: 10;MiLightv1;f746;01;0000;ON
----->2018-04-02 13:58:30.251 dzVents: Debug Note<-----
2018-04-02 13:58:30.253 (RFLink433) Lighting Limitless/Applamp (Garten Pool)
If I now uncomment the if condition and want to print the line "print(sensorwu..'_Temperature')", I do not get any properly output:

Code: Select all

2018-04-02 14:00:48.615 User: Admin initiated a switch command (30/Garten Pool/On)
2018-04-02 14:00:48.616 RFLink Sending: 10;MiLightv1;f746;01;0000;ON
----->2018-04-02 14:00:48.814 dzVents: Debug Note<-----
----->2018-04-02 14:00:48.814 dzVents: WU-THB_Temperature<-----
2018-04-02 14:00:48.816 (RFLink433) Lighting Limitless/Applamp (Garten Pool)
I just do my first steps with Domoticz and LUA - have some small blockly scripts, some door sensor and milight bulps running.

Hope you can give me a idea how to solve or understand my problem :-)

User avatar
jvdz
Posts: 1463
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Get temp only from Weather Underground

Post by jvdz » Monday 02 April 2018 14:08

Do you also have a device called "wu" ? If so, try renaming the script to "script_device_test-wu-temp.lua" ( atleast some name that no device has).
Is the devicename WU-THB unique as the other debug lines show nothing which likely means they are nil.

Jos

Extremo
Posts: 7
Joined: Monday 02 April 2018 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Switzerland
Contact:

Re: Get temp only from Weather Underground

Post by Extremo » Monday 02 April 2018 14:18

Just checked, no device called wu there, maybe i renamed a device some time ago from wu to something other. Renamed now the script to script_device_test-wu-temp.lua. Unlucky: Still not triggered due to WU Update, but will be triggered from another sensor:

Code: Select all

2018-04-02 14:17:41.652 (Weather Underground) Temp + Humidity + Baro (WU-THB)
2018-04-02 14:17:41.654 (Weather Underground) Wind (Unknown)
2018-04-02 14:17:41.655 (Weather Underground) UV (UV)
2018-04-02 14:17:41.657 (Weather Underground) Rain (Unknown)
2018-04-02 14:17:41.659 (Weather Underground) General/Solar Radiation (Unknown)
2018-04-02 14:17:59.377 User: Admin initiated a switch command (30/Garten Pool/On)
2018-04-02 14:17:59.379 RFLink Sending: 10;MiLightv1;f746;01;0000;ON
2018-04-02 14:17:59.571 dzVents: Debug Note
2018-04-02 14:17:59.571 dzVents: WU-THB_Temperature
2018-04-02 14:17:59.573 (RFLink433) Lighting Limitless/Applamp (Garten Pool)
Just don't understand it, should not to be so hard to solve this small issue :-)

User avatar
jvdz
Posts: 1463
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Get temp only from Weather Underground

Post by jvdz » Monday 02 April 2018 15:16

It is not just the trigger that isn't working, it is also not showing the device information for these 2 lines:
print(otherdevices_svalues[sensorwu])
print(otherdevices_temperature[sensorwu])
This to me indicates that the tables return nil which normally means the device doesn't exists.
Guess I suddenly see the issue: I see the device having a green icon which means it isn't activated!

Jos

Extremo
Posts: 7
Joined: Monday 02 April 2018 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Switzerland
Contact:

Re: Get temp only from Weather Underground

Post by Extremo » Monday 02 April 2018 15:36

Hi Jos,
that's timing. I just had done some try outs with LUA the last few minutes and noticed the same. I grabed some basic information from one of my milight bulbs (on/off), then switched the command to the temperature sensor, no output. After enabling and waiting some seconds for the next trigger, I got the values - do we have a icon for "facepalm"? ;-)

The script runs now as expected, the dummy sensor get's now his updates.

Thank you very much for your help!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest