Update rules from values in files

  • Platform information:
    • Hardware: Raspberry Pi 4 Model B Rev 1.2 4GB
    • OS: Raspbian GNU/Linux 10 (buster) / Linux 5.10.63-v7l+
    • openHAB version:3.1.0 - Release Build

Hi guys. Related to high energy prices, I have some rules that switch on and off the hot water tank. The times vary from day to day. Instead of using the web interface, I was wondering if there was any way to update/set the rules by using files. Like:

Rule 01 - Read value in /tmp/elec/morning-start.txt (02)
Rule 02 - Read value in /tmp/elec/morning-stop.txt (05)
Rule 03 - Read value in /tmp/elec/afternoon-start.txt (13)
Rule 04 - Read value in /tmp/elec/afternoon-stop.txt (16)

Thanks for your help. :slight_smile:

You can

  • use the exec binding to run a shell script and set an item to the shell script’s returned value.
  • use a linux cron job to extract the files’ content and set items’ content to the files’ values using REST API calls

Would the iCalendar binding be a solution? iCalendar - Bindings | openHAB
You could trigger individually for every day end have the required values in the calendar.
Not sure if that makes sense for you. I control the heating with that.

To add to @Wolfgang_S’s suggestions, you could use something like

val fileContents = executeCommandLine(java.time.Duration.ofSeconds(1), "cat", "/path/to/file")

Then it’s up to you to parse the file.

Thanks a lot guys for your replies. :slightly_smiling_face: I will need to check a bit more on the solutions proposed, and it may take some time before I could have a try to implement them.