Virtual weather devices

From Domoticz
Jump to: navigation, search

This is a tutorial to help you add weather information from Weather Underground ( to your Domoticz interface.

Update: Weather Underground will no longer provide free weather API keys. So, the description below is not valid anymore. 

As an alternative you can use Dark Sky (previously called See Weather forecast from in Domoticz

1. Sign-up for a free API-key

The first thing you need is a API-key from The great thing is that you can make a completely free account.

  • Go to:
  • Click on the orange button with the text "Sign Up for FREE!"
  • Fill in the field under "Create Your Free Account!", read and accept the Terms of Service and Click "Sign Up"
  • In a couple of minutes you will receive an e-mail, with an URL to activate you account. Click this URL.
  • Now log in with your freshly created account.
  • Go to the "Pricing" page:
  • Select the following options:
   * Developer
  • The total price should be $0 USD per month.
  • Click "Purchase Key"
  • Fill in the fields:
   * Contact name: (your name)
   * Project contact e-mail: (your e-mail address)
   * Project name: Domoticz
   * Project website:
   * Where will the API be used: Website
   * Will the API be used for commercial use: No
   * Will the API be used for manufacturing mobile chip processing: No
   * A brief description: "I use the API for the greatest home automation project!" (or something like that ;) )
  • Check the both check boxes. Only if you agree with the requirements and terms of course!
  • Click "Purchase Key"
  • Success! You have successfully subscribed!
  • You can now see your personal(!) API-key (Key ID). You need this key to setup your virtual hardware (next chapter).

2. Add (virtual) hardware

Just like real hardware, you first have to add Weather Underground as virtual hardware. Just see it as a weather station that is going to provide you with weather data.

First you want to know the ID of the weather station at the location you want to use.

  • Go to
  • At the right side of the page, check if "Weather Stations" is selected in the layers
  • Zoom in to the location of your choice
  • Click on a weather station (it's a small balloon with the temperature inside)
  • Now you see a pop-up with detailed information. At the top left you see "Station ID"
  • Copy the ID (or write it down)

Now you can add this weather station to Domoticz

  • Go to your Domoticz web interface
  • At the top right, click on "Setup" -> "Hardware"
  • Use the "Type" dropdown list to choose "Weather Underground"
  • Now fill in the fields:
   * Name: A logical name for the virtual hardware
   * Type: Weather Underground
   * API Key: Fill in your own API-key form Weather Underground
   * Location: Station ID from Wundermap 
   (If you use a Personal Weather Station add "pws:" in front of the Station ID! See FAQ for details)
  • Don't forget to push the "Add" button to save your settings!
  • Make sure the check box 'Accept new hardware' has been ticked!

3. Check your log

Please don't skip this step! Or don't you want to know if your virtual hardware is working?

  • At the top right, click on "Setup" -> "Log"
  • Is the hardware installation successful? Than you see lines like:
   * Wed Jul 10 13:30:00 2013 (Wunderground Utrecht) Temperature + Humidity + Barometric (Utrecht Barometer)

Great! It's working, now check the next chapter!

  • Is the hardware installation UNsuccesfull? Than you see errors like:
   * Error: Wed Jul 10 13:40:30 2013 WUnderground: Invalid data received, or unknown location!

That's too bad! Check the FAQ chapter for more help!

4. Add (virtual) Devices

Now the real fun begins! Your virtual weather station is providing you with weather data and you want to see this in your Domoticz interface!

  • At the top right, click on "Setup" -> "Devices"
  • You can see up to 5 new (virtual) devices:
   * Barometer
   * Wind (chill)
   * UV index
   * Rain
   * Visibility
  • In this example we are going to add the "barometer" to your interface. You can repeat this step for every device you want to use.
  • Click on the green arrow at the end of the line of the barometer (type: Temp + Humidity + Baro)
  • In the pop-up type a logical name.
  • Let's say this barometer is in Utrecht, you can name it "Utrecht barometer"
  • Press "Add Device" to save the name and add the device to the interface.
  • You can see that the green arrow has changed to a blue one.
  • Now quickly click in the top on "Weather" or "Temperature"! Wow, that's cool!

Scraping only temperature

By default, after you have added the device by clicking on the arrow mentioned above, the device you can see under 'Temperature' will have multiple values (barometic pressure, humidity etc).
If you want to use something like outside temperature in a Blockly event, you need to have the single value, and not the humidity etc.

You can do this by creating a virtual sensor directly in the web interface.

  • Go to Setup --> Hardware
  • Create a new virtual Dummy hardware
   * Enabled: Yes
   * Name: Something like 'WeatherData'
   * Type: Dummy (Does nothing, use for virtual switches only)
   * Data Timeout: Disabled

After that, click on 'Create virtual sensor'. Create a sensor with type 'Temperature'. Then go to Setup --> Devices and search the sensor you just created. Click on the green arrow to add it to your used devices. Fill in a recognizable name and you are good to go.
Go back to the devices list, and note the IDX of the virtual sensor you just created.

  • Go to /home/pi/domoticz/scripts/lua/ and create a new file, named 'script_device_sensorWU.lua'.
  • Put the following code in it:
--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
--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 = 'ChangeME' --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 = 999 --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)

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

return commandArray

Script based mainly on: 'jackslayter' on Domoticz forum, with a small addition from 'nickyb2' to run only when Weather Underground sensor has been updated. Script expanded to parse Pressure and Humidity 5/2015

  • Change the names for 'sensorwu' and the idx to the ones on your system. Save the script.
  • If you go to 'Setup' --> 'Log', you should see something like Script event triggered: /home/pi/domoticz/scripts/lua/script_device_sensorWU.lua every 10 minutes
  • Go to 'Temperature', and you should see your virtual sensor having the same value as the Weather Underground sensor, but now only a temperature and no other values.

    Mission completed, the virtual temperature sensor can now be used in events.

5. FAQ

Something gone wrong? First check this FAQ! Can't find your answer here? Maybe you can find it in the forum:

Q: I see an error in the log files, what to do first?
A: Please double check if you filled in the right API-key! In chapter 1 you can read where to find the API-key.

Q: I see an error like "Error: Wed Jul 10 13:40:30 2013 HARDWARENAME: Invalid data received, or unknown location!"
A: So you are sure the API-key is right? Then check the location you filled in with the help of this webpage:

* Replace PERSONAL-API-KEY with your own API-key
* Replace LOCATION with the right location

Some LOCATION examples:

* utrecht_netherlands (city followed by country)
* EHAM (Airport code)
* 06260 (zipcode, works only in US)
* pws:IUTRECHT60 (ID of the weather station)*(1)
  • If you fill in a right location, you see a webpage with a lot of code. In the code you can see city, country, coordinates, temperature, etc. Now copy the LOCATION and paste it in Domoticz (chapter 3).
  • If you fill in a wrong location, you see a webpage with a short code. In the code you see "error" and "description: No cities match your search query" Now keep changing the LOCATION untill you have found an existing location that works. *(1)
  • If you fill in a location, that exists more than once (like Utrecht, Netherlands and Utrecht, South Africa), you see a web page with a short code. In the code you see that there are more than 1 results. Now try to narrow down the results by changing the LOCATION. Instead of "Utrecht", try "Utrecht_netherlands".
  • If you fill in a location, that exists more than once (like Emmen, Drenthe and Emmen, Overijssel), you see a web page with a short code. In the code you see that there are more than 1 results. Now try to narrow down the results by changing the LOCATION. Instead use the ZMW (like zmw:00000.17.06279) or use coordinates for your location (like 52.790422,6.899169).
  • If you fill in a wrong API-key, you see a webpage with a short code. In the code you see "error" and "description: this key does not exist". Check your API-key, you filled in the wrong one..

*(1) It looks like Wunderground uses no consistent ID's for the weather stations. For example an Airport weather station has a different ID than a Personal Weather Station (PWS). If you are sure the ID is correct, than try to add 'pws:' in front of it (or delete 'pws:'). For example, change IUTRECHT60 to pws:IUTRECHT60, or change pws:EHAM to EHAM.

Q: I want to add more than one virtual weather stations (hardware), is this posible?
A: Yes, you can add up to 3 virtual weather stations (hardware), with a free Weather Underground account. Just repeat the steps in chapter 2 and 3.

Q: Why can I not add more than 3 virtual weather stations (hardware)?

A: With a free Wheater Underground account, you can do 500 requests a day. So, 6 updates every hour, is 144 updates per day (per virtual weather station). 500 divided by 144 is 3.5. Thats why there is a maximum of 3 virtual weather stations (hardware).

Q: Why does my virtual device say N/A
A: The weather station is not sending information at the moment. N/A stands for Not Available.

Q: How often is the data updated?
A: Domoticz checks every 10 minutes for new data. It depends on weather stations on Weather Underground if new data is available. Some stations only update once in the 30 minutes.

Q: What is Weather Underground (also known as Wunderground)?
A: Please read:

Q: Can I share my personal API-Key with my friends or post it on the internet?
A: Yes you can, but no, please don't! It is a personal key, that can only be used 500 times per day.