Switch Relays Based on TIme

Hi,
I am new to OpenHabian and Automation Systems.
I am trying to implement an automation system that will switch on the lights based on local time.
I am using Raspberry Pi3B with 4 Relay Board. Till now I am able to setup the openHabian 2 on my Raspberry and able to turn Relays On or Off using the Basic UI and Android Application. However, I need these to be automated based on time.

I tried finding this out on google but till now I am not able to get any solution.
Request all developers and experts to help me out in this.

Thanks in Advance.

You don’t provide a lot of specifics so:

Thanks for the links.
I went through them and gained some knowledge about Actions and Rules.

I then explored Rule Engine Experimental and able to configure the timers. However, the event is now triggering at specific time (which I set in rule).

Is there any way I can check a time range and based on that trigger my event. For example, if the time is in between 2PM and 3PM then my GPIO position will be high otherwise low?

Note the “Experimental” in the ERE. The ERE is a work in progress, has almost no documentation, and almost no one is using it yet.

So the answer to your question is :man_shrugging:

A key thing to understand about Rules, whether they are ERE or Rules DSL, is that they are event driven. They run when certain events happen. In this case they run at the times that you specify. So if you have one Rule to run at 2PM that turns the GPIO to high and another Rule to run a 3PM that turns the GPIO to low then you will get the behavior you are after.

Thanks for the reply sir.
As of now I have configured the rules like what you specified.

However, let’s say due to some power failure (common in my country India) the server restarts after my configured time of 2PM and not turning GPIO High again.
I can understand that the Rule Engine is in experimental state and hence can not be in full function.

As I am totally new to Linux and Raspberry, is it possible to get Step by Step guide on how to write scripts, where we need to save the files, how to configure the files in Open Hab, etc.

Appreciate you help as always.

For RPI with OH installed via apt-get (openhabian image) the file are located at /etc/openhab2

So from the command line type this: cd /etc/openhab2 then hit enter.
Now type this: ls then hit enter

You should see all the directories like items, things, sitemaps, etc…

To add an item to the items directory type cd items then enter. Now your in the items directory and can create an item using this: sudo nano test.items hit enter. Its a blank screen so you will need to create an item then press Ctrl+x then Y and enter to save.

For rules its the same except you create the rule in the rules directory.

Have you looked at installing VSCode with the OH addon? This is a much easier way to create your files and has code completion. Just do a search on the forum for a guide to setup.

Hope this helps.

You trigger the Rule at System started to calculate what state the GPIO should be in in that situation.

Thanks to all for helping me out.
Finally, I accepted that Experimental rules do not serves my purpose (at-least as of now).
So, I have written the scripts to achieve what I requested originally.

I will post my scripts here once those are in stable state later this week end.

Thank you. This gives me some idea on the file structure of OpenHabian. I am able to write my rules now and execute them as required.
These rules do not display in REE but as far as those as working I am fine with them. :slight_smile:

Thank you sir for pointing me to right direction.