Get Weather Prediction

From Domoticz
Revision as of 07:36, 3 September 2015 by ThinkPad (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Purpose

This script will trigger a bash script every time device change state to on. It is use to give the weather predictions.

Dependencies - hardware / software / operating system

This script will work on all type of hardware / software / operating system.

It could be use to trigger any bash script such :

Domoticz Setup - switches, variables, version

  • Create a virtual lightswitch. e.g. : "Talk - Weather Now"
  • Replace "sensor_virtual" variable by your virtual lightswitch device name. e.g. : "Talk - Garbage"
  • Replace "sensor1, sensor2, sensor3, sensor4" variable by your weather station device name. e.g. : "Weather Station - Temp Humidity"
  • Replace google_voice.sh by the name of your bash script
  • Make sure google_voice.sh is located in : /root/domoticz/domoticz/scripts/google_voice.sh
  • Make sure google_voice.sh is executable : sudo chmod +x google_voice.sh
  • Change the text you want to hear. e.g. : "Prediction : Sunny"

Installation instructions

Copy this script in your domoticz\scripts\lua\ folder.

Script with comments

       -- script name : script_device_weather.lua
       -- This script will trigger a bash script every time the device "Sensor" change status
       -- Create a virtual lightswitch. e.g. : "Talk - Weather Now"
       -- Replace "sensor_virtual" variable by your virtual lightswitch device name. e.g. : "Talk - Garbage"
       -- Replace "sensor1, sensor2, sensor3, sensor4" variable by your weather station device name. e.g. : "Weather Station - Temp Humidity"
       -- Replace google_voice.sh by the name of your perl script
       -- Make sure google_voice.sh is located in : /root/domoticz/domoticz/scripts/google_voice.sh
       -- Make sure google_voice.sh is executable : sudo chmod +x google_voice.sh
       -- Change the text you want to hear. e.g. : "Prediction : Sunny"


       local sensor1 = 'Weather Station - Temp Humidity'
       local sensor2 = 'Weather Station - Wind'
       local sensor3 = 'Weather Station - Rain'
       local sensor4 = 'Weather Station - UV'

       local sensor_virtual  = 'Talk - Weather Now'
       local sensor_virtual2 = 'Kitchen - Door Sensor'
       local sensor_virtual3 = 'Hall - Door Sensor'

       commandArray = {}



       --Weather station data:
       if ((devicechanged[sensor_virtual] == 'On') or (devicechanged[sensor_virtual2] == 'Open') or (devicechanged[sensor_virtual3] == 'Open')) then
       sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[sensor1]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
       sWeatherTemp = tonumber(sWeatherTemp);
       sWeatherHumidity = tonumber(sWeatherHumidity);
       sWeatherUV = tonumber(sWeatherUV);
       sWeatherPressure = tonumber(sWeatherPressure);
       sWeatherUV2 = tonumber(sWeatherUV2);

       --os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Temperature is " .. sWeatherTemp .. "degrees ")
       --os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Humidity is " .. sWeatherHumidity .. "% ")
       --os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV is " .. sWeatherUV .. " ")
       --os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Pressure is " .. sWeatherPressure .. "hpa ")
       --os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV2 is " .. sWeatherUV2 .. " ")

       --print("Weather station: Temperature is " .. sWeatherTemp .. " ");
       --print("Weather station: Humidity is " .. sWeatherHumidity .. " ");
       --print("Weather station: UV is " .. sWeatherUV .. " ");
       --print("Weather station: Pressure is " .. sWeatherPressure .. " ");
       --print("Weather station: UV2 is " .. sWeatherUV2 .. " ");




       ------------------------------------------------------------------------

       --Windmeter data:
       sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[sensor2]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")

       sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
       sWindDirection = (sWindDirection);
       sWindSpeed = tonumber(sWindSpeed);
       sWindGust = tonumber(sWindGust);
       sWindTemperature = tonumber(sWindTemperature);
       sWindFeel = tonumber(sWindFeel);

       --print("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
       --print("Windmeter: Winddirection is: " .. sWindDirection .. " ");
       --os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Winspeed is " .. sWindSpeed .. "m/s ")
       --print("Windmeter: Windspeed is: " .. sWindSpeed .. " ");
       --print("Windmeter: Windgust is: " .. sWindGust .. " ");
       --print("Windmeter: Windtemperature is: " .. sWindTemperature .. " ");
       --print("Windmeter: Windfeel is: " .. sWindFeel .. " ");

       ------------------------------------------------------------------------

       --Rainmeter data:
       sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[sensor3]:match("([^;]+);([^;]+)")

       sRainmeterCurrent = tonumber(sRainmeterCurrent);
       sRainmeterTotal = tonumber(sRainmeterTotal);

       --print("Rainmeter: Actual rain is: " .. sRainmeterCurrent .. " ");
       --print("Rainmeter: Total rain is: " .. sRainmeterTotal .. " ");


       ------------------------------------------------------------------------

       --UV data:
       sUV, sSolar = otherdevices_svalues[sensor4]:match("([^;]+);([^;]+)")

       sUV = tonumber(sUV);
       sSolar = tonumber(sSolar);

       --print("UV: UV Strength is: " .. sUV .." ");
       --print("UV: Solar radiation is: " .. sSolar .." ");

       ------------------------------------------------------------------------
       --output

       --temperature 
       if (sWeatherTemp < 15.0) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Temperature is " .. sWeatherTemp .. "degrees and it is cold")
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Humidity is " .. sWeatherHumidity .. "% ")
       else
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Temperature is " .. sWeatherTemp .. "degrees and it is warm")
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Humidity is " .. sWeatherHumidity .. "% ")
       end	

       --prediction
       if (sWeatherPressure<1000) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Prediction : Rain")
               if (sRainmeterCurrent > 0)  then
               os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh and it is raining now")
               end
       elseif (sWeatherPressure<1020) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Prediction : Cloudy")
       elseif (sWeatherPressure<1030) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Prediction : Partially Cloudy")
       else
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Prediction : Sunny")
       end

       --windspeed
       if (sWindSpeed > 50) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh Prediction : Windspeed too high")
       end

       -- UV
       --wiki http://en.wikipedia.org/wiki/Ultraviolet_index
       if (sUV<3) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV is a Low danger from the sun's UV rays for the average person")
       elseif (sUV<6) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV is a Moderate risk of harm from unprotected sun exposure")
       elseif (sUV<9) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV is a High risk of harm from unprotected sun exposure")
       elseif (sUV<11) then
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV a is Very high risk of harm from unprotected sun exposure")
       else
       os.execute ("/root/domoticz/domoticz/scripts/google_voice.sh UV a is Extreme risk of harm from unprotected sun exposure")
       end



       end

       return commandArray

Example of use (if relevant) i.e. output files / screen displays

N/A