APNT-78 - Extending Sprinkler Control in Fibaro Home Center

This guide shows how to extended the Fibaro Home Center 2's Sprinklers Panel's capabilities so that you can remotely adjust the watering period and automatically delay the next water cycle if the Fibaro weather reports show it's raining.

In the previous example APNT-77 - Controlling Sprinklers we introduced the Fibaro Sprinklers Panel that is available in the Fibaro Home Center 2 (HC2) Z-Wave Controller.

Extending the Sprinkler Panel Control

The Sprinklers panel allows you to manually add a 'Rain Delay' and increase/decrease the water cycle time from within the Sprinklers panel (see APNT-77 for details), however, you can't do this from the current smartphone app and you can't directly change them from a standard Home Center Scene.

By creating a Virtual device, together with a little bit of LUA code, you can have control of these functions and you can use a standard scene to adjust them based on the weather.

This guide shows you how to:

  • Create a Virtual Device in Fibaro Home Center
  • Program the buttons to control the Sprinkler Panel's 'Rain Delay' and 'Adjust Water' functions
  • Create a scene to automatically delay the sprinkler cycle if it's raining or stormy

Note: This can only be used in Fibaro Home Center 2 (HC2) as it requires LUA coding - it cannot be used in Fibaro Home Center Lite (HCL)


Sprinkler Virtual Device

A Virtual Device is just what it sounds like, a device that is not a physical device, but one created in Home Center to control other devices. This example shows a Virtual Device that can change the Sprinkler Panel's 'Rain Delay' (0, 24h, 48h) and 'Adjust Water' (0, 10%, 20%) values.

Virtual Device to control 'Rain Delay' and 'Adjust Water'Figure 1: Virtual Device to control 'Rain Delay' and 'Adjust Water'

Create the Virtual Device

  • In the Home Center go to Devices > Add Remove Devices
  • In the Virtual Device section click 'Add'
  • Give the device a Name
  • Choose a Room from the drop-down list
  • IP Address - Enter the Home Center's IP Address
  • TCP Port - Enter 80 (this is the port used by Home Center)
  • Click the 'Save' icon on the right-hand sidebar

Creating a Virtual Device for the Sprinkler PanelFigure 2: Creating a Virtual Device for the Sprinkler Panel

Create the Buttons

The Virtual Device needs two rows of three buttons - the first row controls the 'Rain Delay' and the second controls the 'Adjust Water' value.

  • Go to the Virtual Device's 'Advanced' tab
  • Scroll down to the 'Choose set of Buttons' section
  • Select the 'Three button per line' - this will give us a three buttons
  • Click the 'Add set' button
  • Add a second row of three buttons (for the Adjust Water control)
  • Click the 'Save' icon on the right-hand sidebar

Creating a Button in the Virtual DeviceFigure 3: Creating a Button in the Virtual Device

Add the LUA Code

Each button will be controlled by a simple LUA script that takes the 'Rain Delay' or 'Adjust Water' value from the Sprinklers Panel, changes the value and then updates the panel.

  • Scroll down to the first button and name it - '0h' in this case (for zero hours delay)
  • Select 'LUA' (bottom of the bottom editor)
  • Paste the LUA code (below) and make changes for your system (HC2 IP address, username and password)
  • Click the blue 'Save' icon on the right-hand sidebar
  • Test the button in the 'Debug' window if you wish and check that the Rain delay has been changed into the Sprinklers panel

LUA Code

-- Set authentication

HC2 = Net.FHttp("192.168.1.162",80)

HC2:setBasicAuthentication("admin", "admin")

fibaro:debug('Button LUA Triggered: ')

-- get data table from the Sprinklers Panel

response ,status, errorCode = HC2:GET("/api/panels/drenchers")

jsonTable = json.decode(response)

fibaro:debug('Rain Delay Value: ' ..jsonTable.rainDelay);

-- change data in LUA for 0 hours delay

jsonTable.rainDelay = 0

fibaro:debug('Rain Delay New Value: ' ..jsonTable.rainDelay);

-- send updated table to panel

json = json.encode(jsonTable);

HC2:PUT("/api/panels/drenchers", json)

fibaro:log("ready")

fibaro:debug('Button LUA Finished: ')

LUA Explanation

The LUA code is split into sections by comment lines (which you can remove), it also includes several debug lines to help you test it within in the Virtual Device's debugger.

  • The first section specifies your HC2's IP Address - you need to add the correct IP address
  • Enter your correct username and password in the second line (admin & admin in this example)
  • The second section gets the Sprinkler panel's data table from HC2
  • The 'rainDelay' value is changed in the third section - to Zero in this case
  • The final section sends the data table back to the Sprinkler panel with the new value for 'rainDelay'

Debug lines: The blue lines (starting 'fibaro:debug) are debug lines which display values in the debug window - you can use these to confirm that the code is running correctly. You can delete these after the button is working.

Adding the IR Command String to the ButtonFigure 4: LUA code in the Virtual Device's Button'

Configure the other buttons

Now you need to configure the two remaining 'Rain Delay' buttons and the three 'Adjust Water' buttons, by repeating the above process.

  • 24h - change rainDelay line to jsonTable.rainDelay = 24
  • 48h - change rainDelay line to jsonTable.rainDelay = 48
  • 0% (Adjust Water) - change rainDelay line to jsonTable.adjustWater = 0
  • 10% - change rainDelay line to jsonTable.adjustWater = 10
  • 20% - change rainDelay line to jsonTable.adjustWater = 20
  • Click the blue 'Save' icon on the right-hand sidebar

The final Virtual device is shown in Figure 5, this has the Sprinkler icon rather than the standard Virtual Device icon - see APNT-72 - Changing Fibaro Home Center Icons. You can now make changes to the Sprinkler Panel's values without having to open it, and just as importantly, you can now change these values automatically from a Fibaro Scene.

Virtual Device to control 'Rain Delay' and 'Adjust Water'Figure 5: Sprinkler Virtual Device with updated icon

Automated Weather Scene

We can now use the Sprinkler's Virtual Device as part of a scene to delay the sprinkler cycle by 24h if it has rained.

Home Center has a built-in weather report which it downloads regularly from Yahoo weather, we use this to determine if it has been raining.

Virtual Device to control 'Rain Delay' and 'Adjust Water'Figure 6: Sprinkler Delay Scene based on Weather

  • Create a scene - take a look at APNT-61 - Creating Scenes in Fibaro Home Center
  • Choose 'Weather > Weather Conditions from the trigger drop-down menu
  • Add a Weather condition for Rain AND and second condition for Storm
  • Add a Virtual Device row with the '24h Delay' button selected - Button 12 in this example
  • The example scene also includes a Push notification to alert you that HC has delayed the next sprinkle cycle - See APNT-76 - Home Center Notifications

Final Word on LUA

This guide is one way to create an automated scene to delay the water cycle. Alternatively, you could use a single LUA scene to get the values and change them based on weather conditions, or you could have a separate LUA scene to control them based on the weather - replacing the standard 'block' scene we've used in this example. You have lots of options to refine the control within Home Center.

Reference

This application note is based on testing by Vesternet as well as many useful forum posts from the users of the Fibaro Forum.

Related Information