Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Using KNX or EMS for demand shaping?

Tags: #<Tag:0x00007fe7abf6faf0> #<Tag:0x00007fe7abf6fa28> #<Tag:0x00007fe7abf6f960> #<Tag:0x00007fe7abf6f898>

Hi all,

I’m getting a Stiebel Eltron heat pump next year, and will be switching to Octopus Agile, so I am looking to control the energy usage so that I can avoid filling the buffer tank or DHW during peak periods, and pro-actively do that during cheaper periods.

Stiebel Eltron heat pumps can have an Internet Service Gateway which has web and mobile apps - which also enables their other Smart Home interfaces, including KNX and EMI.

It doesn’t seem like there are any documented APIs to control this from outside the home, so the “cheap and cheerful” IFTTT approach doesn’t seem like it’s easily accessible, although that might be possible once I get in to the web interface as there must be an API somewhere there… :slight_smile:

Locally, it seems KNX-IP lets you access the SG-Ready value.

EMI is also apparently an open spec, and incidentally is also supported by my Bosch tumble dryer, and I can’t find many links about it besides you can buy a “SMA Sunny Home Manager” which uses EEBus and SEMP to turn a variety of (mostly German) appliances on and off depending on sun/battery/etc status - provided, I assume, those things are also using this system. It seems to work around appliances submitting an energy plan, and the manager guiding when that energy should be used for maximum efficiency.

EMI seems a lot more complex - and as I will have relatively small panels, and big electricity load and battery that will store any excess by itself, I doubt solar optimisation will help much for me compared to just being responsive to agile pricing.

Maybe KNX-IP setting the SG-Ready value is a good place to start and will be sufficient? The modes are 1 = totally off (during peak pricing), 2 = auto, 3 = please use more (during a low price period?), 4 = maximum warp (during plunge pricing). Has anyone looked at this or similar?

Thanks,
Rob

Hello @ramcq and welcome!

Looks like the KNX/IP interface allows you to control quite a bit https://www.stiebel-eltron.co.uk/en/service/smart-home/knx.html, you could probably change either the room or flow temperature set points and reduce these to reduce output during peak?

I dont personally have experience with KNX but it looks like there are a lot of resources for control via OpenHab or NodeRed or libraries available in a number of different programming languages.

Im controlling my Mitsubushi EcoDan but its via simple volts-free contacts and an analog voltage input on the controller to set the desired flow temperature. Id be interested to learn more about how KNX works, perhaps it’s something that could be integrated in future emoncms demandshaper development…

Thanks for the welcome, your reply and looking in to KNX - indeed it seems very powerful for reporting on and fiddling with values in the heat pump. I’m not sure I even need to get into the business of worrying about the set points given the SG-Ready setting (see page 29 of https://www.stiebel-eltron.co.uk/content/dam/ste/cdbassets/current/bedienungs-_u_installationsanleitungen/ISG_KNX_IP__4cee200f-ab01-11e6-81c5-005056a95add.pdf ) gives those four none/auto/more/loads options. To me that makes a little more sense as it would let the other settings prevail - eg never heating the buffer tank if there is no heat demand anticipated due to the program or external weather.

Thanks for the pointers to OpenHab and NodeRed too - I had seen these mentioned elsewhere. Can you expand a little on how I might join together the demand shaping with these - is there a source of events that the demand shaper would export, and then I do something on the other end to respond to the “need more power captain!!” - or is it a matter of patching the demandshaper module to understand a new type of demand it can control, and send the right events out (MQTT?) to have the KNX messages sent?

Your probably best doing this outside of the emoncms demandshaper module for now, perhaps reacting to the agile pricing directly in nodered…

The demandshaper module doesnt cater very well yet for heating control. Whilst I did add a basic heatpump monitor device support to the module, it’s just doing basic on/off and setting the flow temperature not really controlling the heat pump in relation to the agile signal.

Im working on a python script to automate my own heatpump control, and Im just experimenting with reducing the set point through the agile peak at the moment, but its doing that based on a manually set profile (knowing that 4-7 will always be more expensive) at the moment rather than dynamically adjusting in relation to the precise pricing of the agile tariff. I can just set a slightly warmer period say 3-4pm and then reduce the set point after that gradually until 7pm before boosting it back up again after that…
I will share the script when Im a bit further with it, but it is quite specific to my installation I guess…

@borpin and @glyn.hudson may be able to give you some pointers on NodeRed or OpenHab

My go to for home automation is Home Assistant and there is an integration for this make of HP https://www.home-assistant.io/integrations/stiebel_eltron/ - might not be the right model, but if they use a common API it might be OK.

HA has got sophisticated automation mechanism, but less good on the scheduling side. I use a HACS add-in called Schedy to schedule control of the set point temperatures on the climate integration, and then the climate integration controls the actual switching.

I do something similar with HA, AppDaemon4 & Shedy.(hass-apps). For example I control the max/min temperature of the DHW tank depending on time of day - Hotter, and higher minimum during a shower period, cooler rest of day for hot water (more time to recover so can be allowed to get colder) No heating of tank unless UFH lowers the temperature too far.

With those tools, it is very easy to do and to change.

1 Like

I’ve paid the deposit for the battery/solar/ASHP, and have switched to Octopus so I can order a smart meter and then get Agile… I’ve also hooked up my EmonTx so I have some nice graphs of how much my UFH is costing me, although all of my CTs are inside the CU and I don’t have an overall use feed yet. Oops. Anyway - this kit being installed will be months out - but I’ve been having a slow day at work, so I’ve been playing with Node Red as a way to fiddle with some of the APIs. :slight_smile:

I’ve modified https://github.com/JonathanPerkins/octopus-agile-price with some hardcoded thresholds to derive a SG Ready signal (> 15p off, < 8p boost, < 0p force) which seems to be working reasonably well, and I can add a KNX output to it to try and control the heat pump when I have it.

I also realised, reading some other forum threads, that if I (or anything else - eg MyEnergi Zappi) implements Agile responsive loads, I must also change the Tesla Powerwall into backup mode (ie, don’t discharge unless the grid is interrupted) otherwise it will valiantly discharge itself in an attempt to power the shifted loads whenever the Agile price criteria is met. :man_facepalming:

@TrystanLea Do you have any support / plans for controlling batteries in DemandShaper? I guess that would be a relatively easy place for me to start as initially it kind of just needs to be the logical OR of any other demand being switched on, and the Powerwall has a LAN API that can be used to switch modes.

After that I guess if we wanted to roll the heat pump in, assuning KNX behaves, we’d need to teach DemandShaper about devices which weren’t just boolean (to boost the energy usage), as we can also force it off during peak periods and on during plunge pricing.

Great, nice work!

It would be great to add support for batteries but it’s not something Im working on at the moment, @johnbanks did you look at control of the power wall, Im sure there was a discussion about this recently?

@ramcq

Yes – I’ve found PowerWall to be a problem when using Demand Shaper for EV charging.

Instead of charging the EV at cheap night rates, PowerWall discharges to the EV. The solution is to set the Powerall Reserve % to the current % when the EV starts charging starts and then set the Reserve % back to zero when EV charging finishes. This also means the house demand is supplied from the grid during EV charging rather than from PowerWall.

And given it’s the middle of the night, the process needs to be automated.

Per this link, with the latest firmware, accessing PowerWall on the home network to make these changes is no longer possible:

It is necessary to use the API associated with the Tesla Mobile App.

My automate-the-whole-process is still a WIP but these elements are now working:

PYTHON script to get an access token (valid for 45 days):


"""

PURPOSE ...

Get a new Access Token and save it to a file

Access Tokens expire after 45 days

So run this script monthly via crontab -e

Other scripts can read the current Access Token (acc_tok) from the file by including the following lines ...

f = open("/home/pi/ev-charging-scripts/access_token.txt", "r")

acc_tok = f.read()

"""

import requests, json, datetime

from requests.structures import CaseInsensitiveDict

url = "https://owner-api.teslamotors.com/oauth/token"

headers = CaseInsensitiveDict()

headers["Content-Type"] = "application/json"

data = '{"grant_type": "password", "client_id": "81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384", "client_secret": "c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3", "email": "xxxxxxxxxxx", "password": "yyyyyyy"}'

response = requests.post(url, headers=headers, data=data)

if response.status_code in [200]:

token_dict = json.loads(response.text)

for x, y in token_dict.items():

print(x, y)

else:

print(response.status_code)

x = token_dict["created_at"] + token_dict["expires_in"]

date = datetime.datetime.fromtimestamp(x)

print("Valid UNTIL: " + date.strftime('%Y-%m-%d %H:%M:%S'))

# Over-write the access token in a file (access_token.txt) in the SAME directory as this script

f = open("/home/pi/ev-charging-scripts/access_token.txt", "w")

f.write(token_dict["access_token"])

f.close()

Get the energy_site_id which needs to be done just once & noted:


curl --header "Authorization: Bearer xxxxxxxxxxxxxx" -X GET https://owner-api.teslamotors.com/api/1/products

xxxxxxxxxxxxxx = the Access Token ... do: cat /home/pi/ev-charging-scripts/access_token.txt

This provides a wealth of data including:

"energy_site_id": xxxxxxxxxxxxx,

Make a note of it

PYTHON script to set the Reserve % to the current level:


"""

PURPOSE ...

Set the PowerWall Reserve charge to its CURRENT charge %

"""

import requests, json

from requests.structures import CaseInsensitiveDict

# Enter energy_site identifier ...

en_site = "xxxxxxxxxxx" # the energy_site_id

# Get latest Access Token from file

f = open("/home/pi/ev-charging-scripts/access_token.txt", "r")

acc_tok = f.read()

headers = CaseInsensitiveDict()

headers["Accept"] = "application/json"

headers["Authorization"] = "Bearer "+acc_tok

headers["Content-Type"] = "application/json"

# Get CURRENT charge %

url = "https://owner-api.teslamotors.com/api/1/energy_sites/"+en_site+"/live_st$

reply = requests.get(url, headers=headers)

jsonstr = reply.text.rstrip()

reply = json.loads(jsonstr)

curr_percent = reply['response']['percentage_charged']

print(curr_percent)

# Set the PowerWall Reserve charge to its CURRENT charge %

url = "https://owner-api.teslamotors.com/api/1/energy_sites/"+en_site+"/backup"

# data = {"backup_reserve_percent": curr_percent}

resp = requests.post(url, headers=headers, data=json.dumps(data))

print(resp.status_code)

PYTHON script to set the Reserve % back to zero:


"""

PURPOSE ...

To set the PowerWall Reserve charge back to zero - its normal condition

"""

import requests, json

from requests.structures import CaseInsensitiveDict

# Enter energy_site identifier ...

en_site = "xxxxxxxxxxx"

url = "https://owner-api.teslamotors.com/api/1/energy_sites/"+en_site+"/backup"

# Get latest Access Token from file

f = open("/home/pi/ev-charging-scripts/access_token.txt", "r")

acc_tok = f.read()

headers = CaseInsensitiveDict()

headers["Accept"] = "application/json"

headers["Authorization"] = "Bearer "+acc_tok

headers["Content-Type"] = "application/json"

data = {"backup_reserve_percent": 0}

resp = requests.post(url, headers=headers, data=json.dumps(data))

print(resp.status_code)

Note: All the scripts are in the /home/pi/ev-charging-scripts directory

My next step is to incorporate all this into an overall script that can be run as a cronjob sometime after midnight.

I have a single phase OpenEVSE charger and that can be set up using RAPI over MQTT with one exception – the EV charge to level. In my view, it’s smart not to charge the EV to 100% but better to leave ‘space’ for next day’s free solar charge (hopefully). I have an outstanding forum query on this to @ TrystanLea and @glynhudson:

@ramcq – I’m in the market for a 3 phase EV charger and note that you have a Zappi. Does the Zappi have an accessible API?

Hoping some of this may be of help.

Thanks @johnbanks for the very comprehensive and helpful reply!

Very frustrating to learn we’ll not to be able to talk locally to the Powerwall API any longer. If I didn’t need something mounted outdoors I’d be getting something cheaper I think! I find it quite frustrating to have these devices on my LAN that I have to go via the Internet to talk to in a reasonable way - adding additional dependencies and failure modes - or even can’t, just have to use an app. I have a perfectly good CT from Loop which I can’t bring in to Emoncms at the moment because their new devices and apps are not compatible with the old ones, and they’re shutting the old ones off. :confounded:

That said, my preference is that I wouldn’t need to add code/Pi/etc to automate these things at all, and that they would do what I need by design without any additional fragility complexity to support Agile pricing. Considering that one day we might move or rent this house out - or even that my wife needs to operate it without me - having stuff that “just works” and can be understood by an installer / customer support / etc… is beneficial.

I think between the Powerwall, Evohome, heat pump, etc they can probably be configured to do a reasonable job just pretending its a TOU tariff to start with, and aiming them at the cheaper (on average) periods and avoiding the peaks, and then I am going to regard any additional Agile optimization as a bonus/hobby. :slight_smile:

I don’t have a Zappi yet, but it’s a favoured choice of my local YouTube star electrician, and nice that it has PEN fault detection built in. I got a cheap ChargeMaster under the OLEV grant something like 6 or 7 years ago, but I am seeing the benefit of a smart charger once I get my smart meter. It looks like Zappi’s remote API has been partially reverse-engineered. But, given that Zappi can track Agile by itself, provided other things in the house are configured to use the same price thresholds, I didn’t see API access to the charger as a top priority for plumbing in to other home-grown stuff.

Cheers,
Rob

Hi Rob,

Read your post with interest. I have Stiebel Eltron heat pump with the isg gateway. Stiebel us kindly installed the knx software module on my isg and I’ve managed to communicate with it over KNX. We have a KNX controlled HUF house and I’ve become familiar with KNX programming.
I was wondering how you have got on with your project of linking your Agile tariff. I would like to get a smets2 meter but we are on 3 phase and we struggling to get one,

Anyway, I managed to use KNX to switch the heat pump into accelerated mode but found it reverts to normal mode by itself within 60 seconds. Wondered if you have had any joy with this.

Chees,
Anthony
Milton Keynes

Hi @anthonymckay , great to hear from you. Seems like Stiebel Eltron is a rarer brand in the UK. My install is on hold due to the 2nd lockdown, my wife has some health complications and we have 4 kids at home, so we’ve not really been able to have the surveyors/contractors/etc coming in safely. Similarly, no smart meter yet…

So - I’ve not got anywhere yet - I’ve installed Home Assistant as well and been playing with importing temperatures and power usage into that, but my preference is that the majority of my stuff (EV, HP, battery, etc) either takes care of itself or is centrally scheduled by the likes of EmonCMS rather than having to build all of the scheduling logic in my own automations. Although I might still do some of those for the washer/dryer/etc this is “bonus” compared to the big power consumers.

Interested by your experience with KNX - do you already have a KNX master/controller/… device in your house that the ISG talks to? Or is it the other way around. I wasn’t sure if I would need knxd as a “master” or whether I could have my Pi just talking to the ISG directly.

When you say boost, what are you activating in the KNX interface? I was imagining setting the SG ready value (see page 29 of ISG KNX documentation) to encourage consumption during the cheaper periods (3), totally prohibit it during peak (1) and go wild if there is negative pricing (4). I must admit I am not entirely sure what I expect #3 to do - I was guessing it would turn up the buffer/DHW target temperatures…

Cheers,
Rob

Hi Rob,

So we have a German built Huf house and we had all the lights/blinds/ventilation controlled through KNX. In KNX there is not concept of ‘master’ - it’s a distributed system of intelligent switches and actuators. As part of the house we’ve a big 3-phase air source heat pump from Stiebel Eltron - pretty much everything in the house is German which is not surprising. They installed with it their ISG gateway which is basically a little box that connects to the house IP network as well as to the heat pump. There is a web interface onto the box and through this you can see what is happening with the pump and you can amend settings/schedules/temperatures. Around a year ago the web page changed - it had a new thing called SG Ready on it and I investigated to find out what it all means. Essentially you’ve sussed it out already from that document. So I managed to get Stiebel Eltron UK to software upgrade my ISG gateway to the KNX version. KNX is configured through a Windows PC running a special piece of dongle-protected software from the KNX organisation. It is not the most intuitive thing to program but there are some good training manuals on Amazon for literally a few pounds that explain it all. The downside was the cost of the dongle at around €1,000 but that has enabled me to do a lot of house re-programming that would otherwise have cost several hundred euros per incident going through Germany.
I then had to find the KNX “app” for the knx software tools and I managed that and have now been able to communicate with the heat pump. The key thing being able to set the SG mode as you stated. The ISG has settings for the heating and hot water temperatures for SG mode 3 which as you say is the boost mode - essentially sorting extra energy in the water buffer when energy is cheap.
I would LOVE to be on the Octopus Agile tariff but you need a smart meter and being on 3-phase is a bit of an obstacle at the moment. What I want to do is write some Python to run on a raspberry pi that will suck in the daily tariff sheet and then send KNX messages to boost energy during cheapest periods. That will be a nice tech challenge for me as I haven’t learnt Python yet!

I’d not come across Home Assistance so have gone to read up on it. It appears to have KNX integration which is promising.

Sounds like you’re pretty tech savvy. What setup do you currently have? Are you looking to go on this Agile tariff? I gather you have to have a smart meter first, but haven’t spoken to Octopus for several months.

Anthony

The KNX smart house sounds pretty cool, maybe if I ever flee to the countryside and build my own house, I’ll have to look up Huf… :slight_smile: My current thinking is money/effort spent on decarbonising this house will live on even if we move out.

Currently I just have a boring old gas boiler (with weather compensation, I have been lowering the curve to see if the heat loss calculations hold up for my new radiators - the summary is it feels a touch chilly, but I’m not sure if the boiler isn’t cycling now because it’s oversized for the actual heat demand!), EvoHome thermostats, Octopus Tracker tariff, and a Raspberry Pi running EmonCMS for some energy and temperature monitoring, and Home Assistant and NodeRed for experimentation. I’ve got a quote ready to go for a Stiebel Eltron WPL-25, Tesla Powerwall (I would love something less expensive / more locally controllable but we’re quite keen on the backup functionality and we ideally need an external battery located separately from the consumer unit - so I’m not sure I have many other choices) and 8 solar panels, and I’m awaiting a smart meter so I can change to Agile.

It’s worth adding that with an EV, 4 kids, working from home anyway, I’m not expecting more solar surplus than can fit in the battery, so am not too worried about any demand shaping based on the solar generation - this is why I am interested in Agile to get the cheapest/greenest electricity. Even with the solar panels in, my working assumption is that we will need a fairly solid amount of import, and the things which would be most costly (EV, HP and the battery itself) are the big items to make sure they move to the best times of day.

I’m confident with some good ol’ Open Source I will be able to bypass the $1000 KNX dongle extortion, but beyond that I wasn’t 100% sure on the approach I would end up taking. Start first by setting everything’s time schedules to when Agile tends to be most and least expensive. Then, Node Red is probably the least coding necessary place to experiment with the algorithm and just see if I can poke my SG-Ready signals in to the heat pump once I have it, and then depending on my enthusiasm I might then try and patch the demand shaper to set, and send (perhaps via MQTT <-> KNX?) the SG Ready signals, and schedule the peak and off-peak periods on the Powerwall. I feel like code that is reviewed, distributed, has a UI and other users, etc will end up being more robust and accessible to the world than a more bespoke standalone script or nuanced Home Assistant setup.

Happy to share notes as I learn things and vice versa.

Cheers,
Rob