How to integrate RainMachine with different weather forecast services

From RainMachine wiki page
Jump to: navigation, search

How to integrate RainMachine with different weather forecast services

RainMachine can be integrated with other weather services for which we don’t provide support by default. At the time of the creation of this document multiple weather services are already supported: NOAA, MET.NO, Weather Underground,, NetAtmo. Check our wiki page for information on how to use these weather services. If your desired weather service is not included, a custom weather parser can be written. These weather parsers are small python scripts that fetch weather from different sources (internet service, local sensors, etc) and RainMachine will automatically “mix” this data with data from other running/active parsers.

The RainMachine parser framework will load your custom parser and execute the perform() function inside. Note that your parser must be a class that inherit RMParser (see example below).
1. First develop your code that fetches and parses the data and test it on your development machine. Note any extra python modules that you need
2. Wrap your code in a function named perform() and add it to a class that inherits RMParser (as in example below). Provide parserName, parserDescription and other details.
3. The data that you need RainMachine to see, should be added by using either addValue() or addValues() calls
4. Upload the code (should be a .py file) to your RainMachine. For this follow the guide in the Wiki.
5. Manually run the parser that you created and check for any errors in the logs (in web ui logs can be viewer From Settings->About->View Log)
6. If everything is ok the data should be already in RainMachine database, and your parser will be automatically run on the interval that you specified with parserInterval.

All data that’s passed to addValue/addValues function should be in metric system. Data types (and their measurement units) known by RainMachine are listed below:

class RMWeatherDataType:
    TIMESTAMP = "TIMESTAMP"                 #[Unix timestamp]
    TEMPERATURE = "TEMPERATURE"             #[degC]
    MINTEMP = "MINTEMP"                     #[degC]
    MAXTEMP = "MAXTEMP"                     #[degC]
    RH = "RH"                               #[percent]
    MINRH = "MINRH"                         #[percent]
    MAXRH = "MAXRH"                         #[percent]
    WIND = "WIND"                           #[meter/sec]
    SOLARRADIATION = "SOLARRADIATION"       #[megaJoules / square meter per hour]
    SKYCOVER = "SKYCOVER"                   #[percent]
    RAIN = "RAIN"                           #[mm]
    ET0 = "ET0"                             #[mm]
    POP = "POP"                             #[percent]
    QPF = "QPF"                             #[mm] -
    CONDITION = "CONDITION"                 #[string]
    PRESSURE = "PRESSURE"                   #[kilo Pa atmospheric pressure]
    DEWPOINT = "DEWPOINT"                   #[degC]

Other resources
All default parsers examples can be found here:

Parser Example

from RMParserFramework.rmParser import RMParser  # Mandatory include for parser definition
from RMUtilsFramework.rmLogging import log       # Optional include for logging
import json    # Your parser needed libraries

class ExampleParser(RMParser):
    parserName = "My Example Parser"         # Your parser name
    parserDescription = "Testing parser API" # A description for this parser
    parserInterval = 3600                    # Your parser running interval in seconds
    parserDebug = False                      # Don't show extra debug messages
    params = {}                              # Internal params that can be changed with API call /parser/{id}/params

    # The function that will be executed must have this name
    def perform(self):                

        # Accessing system location settings
        lat = self.settings.location.latitude

        # Other location settings

        # downloading data from a URL convenience function since other python libraries can be used
        # data = self.openURL(URL STRING, PARAMETER LIST)
        # URL = "
        # parameterList = [ ("parameter1", "value"),("parameter2", "value") ]

        # After parsing your data you can add it into a database automatically created for your parser with
        # self.addValue( VALUE TYPE, UNIX TIMESTAMP, VALUE)

        # Adding multiple values at once is possible with

        # Predefined VALUE TYPES
        # RMParser.dataType.TEMPERATURE
        # RMParser.dataType.MINTEMP
        # RMParser.dataType.MAXTEMP
        # RMParser.dataType.RH
        # RMParser.dataType.WIND
        # RMParser.dataType.SOLARRADIATION
        # RMParser.dataType.SKYCOVER
        # RMParser.dataType.RAIN
        # RMParser.dataType.ET0
        # RMParser.dataType.POP
        # RMParser.dataType.QPF
        # RMParser.dataType.CONDITION
        # RMParser.dataType.PRESSURE
        # RMParser.dataType.DEWPOINT

        # For your own custom values you can use
        # self.addUserValue( YOUR CUSTOM VALUE NAME, TIMESTAMP, VALUE)