This template creates a very simple rule that will allow you to control the state of a device based on the electricity that your house is spending. I will call this device ‘the load’. The goal is to have a ‘Solar Switch’ that switches on/off the load only when your solar panels are generating enough power.
The rule should run every x minutes while the solar switch is on. This is achieved with another rule that you can create with the ‘Threshold Alert and Open Reminder’ template (thanks Rich).
So, hands on, here are the steps to create the ‘Solar Switch’.
In Configuration, Model Menu, select a location and Add one Equipment. In the new Equipment you just created, add three points:
- Create the ‘Solar switch’, call it (for example) ‘VSolarSwitchforXXDevice’: Add a point of type ‘switch’, and semantic class status. This will be the switch that you will use to activate the rule, and thus, the device, but only when there is enough solar production. Add a Metadata to define the type of switch that you prefer to use (here I use Default Cell Widget → Default oh-cell).
- ‘Switch off Threshold’: Add a point of type ‘number’ and semantic class power. Add in Metadata the type of control you want to use here (I sugest to add ‘Default List Item Widget’ → ‘Stepper List Item’ - oh-stepper-item).
- ‘Switch on Threshold’: Add a point of type ‘number’ and semantic class power. Add in Metadata the type of control you want to use here (again, I sugest to add ‘Default List Item Widget’ → ‘Stepper List Item’ - oh-stepper-item).
Now we can begin with the Rules. We will need two rules.
-
Rule 1, based on this ‘Solar Switch’ template. This rule will Switch the load On/off depending on the energy consumption of the house and will take into account posible overides in the control of the load (if someone switches on / off the load directly, the rule will deactivate the solar switch and notify you). To complete the template, you will need the points that we defined above. The rule asks for your email account. This is optional: if you set an account (and if you have the Openhab APP instaled), the rule will notify you when thiere is a change in the states of the load or the solar switch.
-
Rule 2 - base on the ‘Open Reminder’ template. This rule will Run rule 1 every n minutes (the number of minutes is up to you). The trigger item will be ‘Solar Switch’, the alert state would be OFF (as the Open Reminder template explains, this rule will work as long as the switch value is not OFF). In the Alert Rule field we must put the ‘solar control rule’ that we created before (with the Solar Switch template). The only two values left to add to this template would be the default initial timeout and the repeat period; I usually set them to 5 minutes (PT5m). Additionally, you can take advantage of this template to configure the times in which we want to leave the system activated (for example, it could be used to turn on the air conditioning in the morning, but only when there is solar energy).
And thats all for this rule. The final point is to find a good balance in the thresholds. You will need to choose between the precision of the values of power consumption that you want to achieve and the number of times that the load will be switching.
Changelog
Version 0.1
- initial release
Version 0.2
- Included some changes suggested by ricoshack.
Resources
https://raw.githubusercontent.com/Vayatoalla/oh-solarswitch-template/main/code.yaml