Control a water heater and ground source heat pump based on cheap hours of spot priced electricity

n = 4;
slices = 12;
min = 0;

The slices = 12 does not make much sense. You want to use just 1 slice between your start and stop and find the cheapest hours from there. You can keep min as 0.

I guess your right as allways, I will keep fine tuning parameters until it gets really good. Power consumption really goes the right way below is s photo of my hourly consumption from 1st of september and as soon as price drops my consumptions peaks. Average idling consumption with two home offices running is 2kw per hour and nightly peak of more than 10kw an hour.

1 Like

August average spot price was 32.4 c/kWh in Finland (incl. tax). If we would have a spot price contract, we would have paid 22.5 c/kWh. In other words, we were 9.9 c/kWh below the average.

Our contract is 14.8 +/- delta, where delta was in August this -9.9. So we pay 14.8-9.9 = 4.9 c/kWh. This translates to 67% discount. :slight_smile:

Here’s the last 7 days consumption vs. spot price graph

1 Like

Well it seems like my timestamps run into some trouble because when rules isn’t run in even hours the time offset for measurments in database can be up 18:20 instead of 18:00 and then the control script doesn’t find any measurment and defaults to 1, so theres still some work to be done with my date time items triggering the funkctions
1 Set hours for ev charger N hours from dateitem1.state and until dateitem2.state this seems to get offsets in influx db so that next script that checks if control = 0 or = 1 and toggle switchitem in OH. I will keep troubleshooting this first of all run the rule every hour but only if ev is connected and the maybe be able to use that time for start time.

First of all Markus a big thanx for all the information you have put down here for others to use!

In our house here in Finland we have the following energy forms - wood/electricity/ground pump/solar heat panels/PV system and an electric car after a month. Our electricity contact is running out in January and we will likely have a spot contract after that. So we will definitely benefit from your work here.

I have been playing with computers, electronics, programming and electricity all my life so I have a basical understanding of related things at a hobbyist level.

I have now been able to set up a openHABian + InfluxDB2 + Add-ons system on a Raspberry Pi 4 fitted on a Waveshare 8-relay board.

The big trouble I have now is to set up the rules and scripts.I have started with only the rule to fetch the FMI weather data by making a time triggered rule that runs the first script part (and put in our location) that calls fmi.js and influx.js. The scripts are set as type ECMAScript 262 Edition 11. Triggering the rule ends in a GraalVM-polyglot error message,

2022-09-13 19:03:23.065 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘5fe8f3d523’ failed: org.graalvm.polyglot.PolyglotException: EvalError: /etc/openhab/automation/js/node_modules/kotikolo/fmi.js

What am I missing here? I have checked, and double-checked, googled for some days now without any progress from here.

Could you please Markus point me in the right direction so I could get on with this very exciting project?

I replied to the other thread where you asked about the ECMA script issue: How on earth can I get my ECMA scripts working on openHABian? - #6 by masipila

I’ll also update the comment marked as the solution so that it mentions that the file permissions must be correctly set up.

Sorry for the inconvenience, hopefully this helps a bit and you’re able to make some progress.

Cheers,
Markus

Hi all

I have this solution running really nice now and I also get estimated needed chargingtime from my Kia via nodered integration that publish car status via MQTT.

Due to the fact that my target time for EV charging is most typically att tomorrow att 06:00, I made some modifications for nibe.js so it doesn’t defaults to 1 but defaults to 2 so I know when there’s no spotprice availible for target time and the compute against midnight, but when it get price for 06:00 it recomputes with correct target time.

I would have been happy is there’s a way to cast some state when prices is updated for tomorrow and whats and when the lowest, highest and whats the average cost for tomorrow or between two dattime items.state.

In that solution I would allow some stuffs like winter preserving my spa to run when price is lower than xx amount regardless if it’s really needed just for bunkering energy in case the coming days is more expensive.

I will try to get the control rules to run ahead of every hour and set some state so that toogle things on or off is done either xx:59 if its off or xx:00 if its on, just to make sure not spend 5 times prices even if it’s just for a minute. That may seem cheap but soem stuff lik ev charger takes a while to get up or down i consumption.

But this soulution is as said really good, we are having an average electricity cost of 2,9SEK abou 0,29EUR and average day price so far for September is 4SEK and bes of all thanks to automation it doesn’t affect our life as much or at all.

/Marcus

I’m super glad to hear that you’ve been able to achieve almost 30% savings with this solution. Moving consumption out from the high-demand peak hours helps the whole society and also helps us here in Finland because we are completely dependent on the import from you guys in Sweden… So please spread the word in Sweden!

This starts to go exactly to the direction which I saw coming. Which is why I originally wrote this:

I’m not saying that those use cases would not be interesting or worth doing, but I personally don’t have time or energy for them with two small kids and curling world championships coming in a month from now. This thread is already almost 100 comments long so I’d kindly ask you to open a separate thread for those use cases. You are more than welcome to add links to those new threads from this topic so that other community members can find them since they are closely related.

If anyone is interested in transforming the code to real bindings, you are absolutely more than welcome to grab the code and continue from there.

Cheers,
Markus

1 Like

Hi,

This is an interesting project. Thank you Markus for providing the instructions and code.
I’m new to OpenHab and I don’t have much programming background. I’m an electronics designer but I have done some Java and C programming. Anyway, I would like to build a system to control the heat pump (Nibe F1226) to run on cheapest hours. First I’m trying to make this work on Windows and later move it to Raspberry Pi.
I think everything is now up and running, but for some reason the data is not saved to InfluxDB. OpenHab is giving the following log info:


When I increase the log level, I can see an InfluxDB related error which says “X-Platform-Error-Code: not found”. InfluxDB is run via Powershell and there I can see errors “database not found” and “unable to write gathered points”.
How do I configure InfluxDB to receive the data correctly?

Are you able to log in to the Influxdb web user interface?

If yes, pay attention to the IP address, port and user credentials and update them to influx.js. after making the updates to influx.js, you need to re-save the openHab rule to make those changes take effect.

Markus

Yes, I can log in to the Influxdb and I have updated the user credentials to influx.js.
I run OpenHab via command prompt using command ssh -p 8101 openhab@localhost and InfluxDB via Powershell with command ./influxd in the influxd.exe folder.
OpenHab opens in address localhost:8080 and InfluxDB in localhost:8086. I have no idea what I’m doing but I feel I’m almost there :smiley:
Do I need to make a query in InfluxDB or should the spot prices appear there automatically after running the “FetchSpotPrices” script in OpenHAb? I can’t see any buckets or data there. I have created an AllAccess API and it is updated to the influx.js.

This is the powershell window view:

You need to create the Influxdb bucket first and have an operational InfluxDB, otherwise the script has no place where it would write the data. The Influx user also need to have write access to your bucket.

Refer to the influxdb tutorials on their website.

Cheers,
Markus

I created a bucket called “autogen”. Do I need to add data to it using some of these options?
image

No, the openhab scripts will enter the data.

Now it seems the OpenHab script creates “spot_price” measurement to the bucket “autogen” but there are no values. I have updated the Entsoe token to the OpenHab script FetchSpotPrices. Also the debug info says “influx.js: Preparing to write 24 points to the database for spot_price” and “influx.js: Points successfully saved for measurement spot_price”.

If you have the measurement, you also have data in it. infkuxdb only creates the measurement when it writes the first measurement point for it.

The default time frame in the influx data explorer is “past 1h” if my memory serves me well. You need to change this to see tomorrow’s prices because they are in the future.

Cheers,
Markus

That was it, thank you Markus! I just needed to change the time frame. My new Raspberry is coming next week :smiley:

1 Like

I have been running this great solution for a couple of month controlling my water heater :blush:

I have an idea trying to visualize for the rest of the family when the spot price is “high” or “low” using a led matrix.

My goal is to have the matrix:

Spot_price above average day = Red Light
Spot_price below average day = Green Light

Can anyone point me in any direction to achieve this, can I simply modify existing code?

Create a new rule that runs every full hour (because that when the price changes).

That rule would run a new script action that would read the spot_price measurement points from your influxDB in the same way as you do when you calculated the on/off hours for your waterheater, calculate if the current hour is above or below the daily average and then sen the command to your lights.

Based on my own experience, the red/green indocator is not very helpful though because if it’s red right now, the obvious follow-up question is “well when is it going to be green then”.

One option is to have a cheap but nice looking tablet as a wall display, and have the daily spot prices visually available over there.

My system has now been up and running without problems for about one month. No changes has been made but today the entsoe.js script didn’t run correctly and no spot prices where added to the influx db. The error message is,

2022-10-24 19:45:28.785 [ERROR] [nhab.automation.script.ui.d023cfcc23] - entsoe.js: Exception parsing spot prices: Cannot read property "period.timeInterval" from undefined

Has anyone else encountered this? Any ideas about what is going wrong?