BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
566 stars 56 forks source link

Octopus Free Electricity Sessions #973

Open jonathanadams opened 1 month ago

jonathanadams commented 1 month ago

Describe the feature

I’ve received a email from octopus today advertising their free electricity sessions.

Is there a way this can be integrated into this integration. For example similar to saving sessions with a sensor or an event? Would be nice to be able to automate based on free electricity.

https://octopus.energy/free-electricity

Expected behaviour

N/A

Use Case

A sensor to be able to automate from.

Confirmation

Gary-Manuel commented 1 month ago

I logged in to make exactly the same request. Would be a great enhancement.

philipdouglas commented 1 month ago

Yeah, me too! 😆 It doesn't look like they've added anything to the API for it, but maybe it will use the same mechanism as saving sessions? I guess we'll see tomorrow...

BottlecapDave commented 1 month ago

Thanks for raising. It feels like this doesn't offer a high tech solution yet as we're opting in via web forms. I too can't see anything in the API regarding these sessions and people have asked if there's an API in the OE forums, but have yet to have a reply.

Once it's available, it'll be a top priority to add it as it will benefit a large number of people.

greedyboyuk commented 1 month ago

Thanks for very thorough answer & future commitment if & when Octopus add it to the API. 🤞👍🤙

plord12 commented 1 month ago

I simply added a calendar entry for tomorrow and created automations from that.

If/when we get an API working, the calendar can be deleted and the automation trigger tweaked.

elyobelyob commented 1 month ago

Same, I've added a calendar entry which will kick off some devices. But at ~4p per kWh on Agile I'll not be saving much. Also had a look through GraphQL stuff and couldn't see anything. I suspect it's more of a marketing thing rather than a full time policy. So, the amount of work to change the API for "2 or 3 sessions before winter" would unlikely happen.

plord12 commented 1 month ago

Yea, exporting the battery charge before the free hour (and then re-charge) is worth more.

chris-y commented 1 month ago

Same, I've added a calendar entry which will kick off some devices. But at ~4p per kWh on Agile I'll not be saving much. Also had a look through GraphQL stuff and couldn't see anything. I suspect it's more of a marketing thing rather than a full time policy. So, the amount of work to change the API for "2 or 3 sessions before winter" would unlikely happen.

I already have a calendar for Power-Ups (which coincide with this first session anyway) to trigger battery charging.

I think this is a test of the "reverse saving sessions" that were announced as part of the extension of the grid balancing schemes. Those aren't due to start until after winter (in winter we get the regular saving sessions, then afterwards we get the reverse), so likely Octopus are running a few off their own back to gauge interest or work out how much to bid, or maybe even inform the process (not sure if there is industry discussion going on but I suspect it's likely). It will probably be merged into the Saving Sessions API when that scheme restarts.

Quickstep3 commented 1 month ago

+1 for this. Have an automation script to trigger everything to max import manually (or at specific time which seems to be 1pm generally) but would be great if for this integration to pick up anything the Octopus API exposes and use that as a trigger

RobinXe commented 1 month ago

With the second one happening today, it looks like the signup only happens once, and then you're opted in for all of them, unlike SSs. Whether this continues to be the case when the move out of trail phase clearly remains to be seen. I too suspect that Octopus are doing this to demonstrate the capability to the Grid.

One thing that occurred to me during the last one, as my solar provided power to fully half of the stuff that I was doing to try to use more energy, is that I'm not entirely sure that it's worth it for IO customers with solar and battery, when you could potentially make more exporting the solar than you're saving against a shifted import cost of 7 p/kWh. Not entirely sure how to quantify it yet, but I'll add it to the list of things to think about when I have time!

Quickstep3 commented 1 month ago

given it's sunny and we've already got a full battery here I've set my solar and battery to export max (i.e. with battery topping up generation to max inverter rating) this morning and can then import and charge the battery for free and export that again later. As battery is rated 10kWh @5kW delta will be 5kWh in at 0p and out (later) at 15p => MAXIMUM +75p not accounting for loses over doing nothing PLUS whatever else we can import (e.g. immersion heater) LESS the local solar generation from 1-2pm.

DavidqStokes commented 1 month ago

As today is the second free energy day I was also thinking about setting up automations to schedule the home battery and th EV to charge. I also was also about to suggest adding an entity for free electricity (if available from the OE API) so would also use this enhancement.

plord12 commented 4 weeks ago

One thing that occurred to me during the last one, as my solar provided power to fully half of the stuff that I was doing to try to use more energy, is that I'm not entirely sure that it's worth it for IO customers with solar and battery, when you could potentially make more exporting the solar than you're saving against a shifted import cost of 7 p/kWh. Not entirely sure how to quantify it yet, but I'll add it to the list of things to think about when I have time!

Yea, good point. I suppose you could set a rule based if it's a sunny day or not.

DavidqStokes commented 4 weeks ago

It depends on your solar setup. I'm on the original FIT scheme and we get paid 65p per kWh for generating, not for export. Any additional free import is worth it as the solar PV only generates 3.2kW, and if we charge the home battery (at 3kW) and the EV (at 7kW), run appliances etc we still use an extra ~8kWh, which is worth 8 x the difference between our day and night rate.

Plus, we're reducing curtailment, which is good for everyone.

craig1410 commented 4 weeks ago

given it's sunny and we've already got a full battery here I've set my solar and battery to export max (i.e. with battery topping up generation to max inverter rating) this morning and can then import and charge the battery for free and export that again later. As battery is rated 10kWh @5kw delta will be 5kWh in at 0p and out (later) at 15p => MAXIMUM +75p not accounting for loses over doing nothing PLUS whatever else we can import (e.g. immersion heater) LESS the local solar generation from 1-2pm.

You don't necessarily lose the solar generation between 1-2pm because some people (like me) have DC coupled solar, so I can absorb solar energy into my batteries, as long as the batteries are not full, regardless of what I'm doing on the AC side. So for the first Free Electricity session, I force exported for an hour before the 1-2pm session then charged my batteries at max charge rate (70A) plus absorbed solar PV at (IIRC) 40A or so (it was a cloudy day) for a total of 110A battery charge current. By force exporting at around 4kW I netted an extra 60p of export and then I imported again for free at around 3.5kW to get my batteries more or less back to where they were. Actually my charge level afterwards was higher due to the simultaneous PV storage.

plord12 commented 4 weeks ago

It would be great if we could find a way to take a set of household settings and auto generate rules.

(where household settings includes electricity supplier details, ev details, solar details, battery details, heating details, goals etc)

Could get complicated, I guess ...

ragg987 commented 3 weeks ago

Is it possible to over-ride the rate during the free periods? At present costs in HA are calculated based on the full rate (~24p for IOG). The results for the first session just dropped in, I imported nearly 6kWh extra during that period. Not too shabby given I generated 3kWh solar power at the same time. But instead of showing a cost of zero it is showing it as £1.45.

craig1410 commented 3 weeks ago

Is it possible to over-ride the rate during the free periods? At present costs in HA are calculated based on the full rate (~24p for IOG). The results for the first session just dropped in, I imported nearly 6kWh extra during that period. Not too shabby given I generated 3kWh solar power at the same time. But instead of showing a cost of zero it is showing it as £1.45.

I think this will be complicated to get accurate because the electricity used during the "free" period isn't actually all free. It's only the EXTRA energy you used compared to your 10 day average, and they even separate out week days and weekends when calculating what "normal" is for you. They also exclude free sessions when calculating normal.

In my case I got told by Octopus that I used 10.47kWh overall and my normal consumption is 0.01kWh so I used 10.46kWh extra. That is 103524% more than normal and worth £2.40 according to them, but that's assuming I used that energy at peak rate when it's far more likely I would have used it at off-peak rate to charge my batteries, or for free from PV.

ragg987 commented 3 weeks ago

@craig1410 that is a good point. I was not clear, was wondering if there was a manual way to override the rate. Potentially retrospectively. I think it's off topic for the original feature request.

BottlecapDave commented 3 weeks ago

I think this will be complicated to get accurate because the electricity used during the "free" period isn't actually all free. It's only the EXTRA energy you used compared to your 10 day average, and they even separate out week days and weekends when calculating what "normal" is for you. They also exclude free sessions when calculating normal.

This is a difficult one, as technically it's still cost you this amount it's just your account will be credited the difference. Some people might not want this deducted because of this technicality.

However I'm currently building the sensors to show the target/baseline for saving sessions, which is a similar calculation. I'm not wanting to overload the the OE APIs to get the data for the target periods, so I'm hoping to try and build up a local copy of this data as I retrieve the previous consumption data. This principle could potentially be used for free electricity sessions, but will be difficult when importing retrospectively via the availale service. Alternatively, I might be able to look at the account balance for certain payloads which indicate credit from these sessions, but again this could be expensive when importing retrospectively.

Either way, it's something that needs to be addressed (along with updating target rate sensors to optionally favour free electricity sessions, but this too could get complicated as it depends on what you're using the sensor for)

Is it possible to over-ride the rate during the free periods? At present costs in HA are calculated based on the full rate (~24p for IOG).

This was never built into the system as it was always assumed OE would provide the correct accurate data :) I'm also not sure it's possible with how HA stores the data, as they store each hour as an ever growing sum. This means if you want to change a record from a few days ago, you need to change all subsequent records.

Gary-Manuel commented 3 weeks ago

A next session start date and time would do me. Just need something to automate the start of a session.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: David Kendall @.> Sent: Friday, August 23, 2024 5:23:37 PM To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Comment @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

I think this will be complicated to get accurate because the electricity used during the "free" period isn't actually all free. It's only the EXTRA energy you used compared to your 10 day average, and they even separate out week days and weekends when calculating what "normal" is for you. They also exclude free sessions when calculating normal.

This is a difficult one, as technically it's still cost you this amount it's just your account will be credited the difference. Some people might not want this deducted because of this technicality.

However I'm currently building the sensors to show the target/baseline for saving sessions, which is a similar calculation. I'm not wanting to overload the the OE APIs to get the data for the target periods, so I'm hoping to try and build up a local copy of this data as I retrieve the previous consumption data. This principle could potentially be used for free electricity sessions, but will be difficult when importing retrospectively via the availale service. Alternatively, I might be able to look at the account balance for certain payloads which indicate credit from these sessions, but again this could be expensive when importing retrospectively.

Either way, it's something that needs to be addressed (along with updating target rate sensors to optionally favour free electricity sessions, but this too could get complicated as it depends on what you're using the sensor for)

Is it possible to over-ride the rate during the free periods? At present costs in HA are calculated based on the full rate (~24p for IOG).

This was never built into the system as it was always assumed OE would provide the correct accurate data :) I'm also not sure it's possible with how HA stores the data, as they store each hour as an ever growing sum. This means if you want to change a record from a few days ago, you need to change all subsequent records.

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2307410868, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBDZ2HRBF6RVFREY7HWTZS5OYTAVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGQYTAOBWHA. You are receiving this because you commented.Message ID: @.***>

8none1 commented 3 weeks ago

I put together something which publishes a JSON object with the start and end times of Power Ups in my region (NB: Power Ups are not the same as Free Electricity Session) here:

https://www.whizzy.org/2024-01-24-powerups-api/

I'm currently adding support for Free Electricity Sessions (FES) too, and I will post here when it's working, likely in the next couple of days. It will use the same concepts but publish to a different JSON object so PUs and FESs will work independently.

Until OE publish a proper API for FES people following this thread might find this new data source useful.

Expect it to be fragile though. The style of the FES announcement emails hasn't completely settled down yet and my egregious use of regex will likely cause problems when it changes. I'm motivated to keep it working though, so a fix probably won't be far away.

Gary-Manuel commented 3 weeks ago

That looks promising. Free Electricity should be easier to automate too as there is no need to opt in each time. Just grab start / end time and date and use those to trigger suitable automations that export prior to the session and then charge back up for the duration of the session. Automations already working but needs manual setting up and switching on. I'll have a closer look at the link you sent later. Thanks for that.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Will Cooke @.> Sent: Friday, August 23, 2024 6:49:12 PM To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Comment @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

I put together something which publishes a JSON object with the start and end times of Power Ups in my region (NB: Power Ups are not the same as Free Electricity Session) here:

https://www.whizzy.org/2024-01-24-powerups-api/

I'm currently adding support for Free Electricity Sessions (FES) too, and I will post here when it's working, likely in the next couple of days. It will use the same concepts but publish to a different JSON object so PUs and FESs will work independently.

Until OE publish a proper API for FES people following this thread might find this new data source useful.

Expect it to be fragile though. The style of the FES announcement emails hasn't completely settled down yet and my egregious use of regex will likely cause problems when it changes. I'm motivated to keep it working though, so a fix probably won't be far away.

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2307543203, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBD3GQ6FWQNWWWQEQ47TZS5YZRAVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGU2DGMRQGM. You are receiving this because you commented.Message ID: @.***>

gcoan commented 3 weeks ago

I put together something which publishes a JSON object with the start and end times of Power Ups in my region (NB: Power Ups are not the same as Free Electricity Session) here:

@8none1 that looks a neat solution but you don't mention anywhere where in the country you live? Power Up sessions started in the East of England but I think they are now available in Scotland and the Midlands so may be different in each area.
I've also seen occasionally slightly different power up sessions between myself and @piansom and we only live about 10 miles apart (I'm in Bedfordshire and he is in Cambridgeshire). We pretty much always get the same sessions but occasionally he or I get one different from each other 🤷‍♂️

The Power Up sessions have been of variable benefit to me, and the free electricity sessions have so far been of zero benefit. The most two recent power up sessions (yesterday and today) coincided with with negative Octopus Agile rates so it wasn't financially worth it to sign up! But more than that, recent Power Up and Free electricity have been on sunny days when I'm generating and exporting more solar than I can charge into the battery so its simply not worth discharging and recharging the battery.

On the subject of how to handle the finances of Free sessions in HA Energy dashboard, I have multiple tariffs on my import utility meter sensor and swap between the 'free' and 'day' rates at appropriate times.

8none1 commented 3 weeks ago

you don't mention anywhere where in the country you live?

Good point. I didn't find a reliable way to get data about PUs in other regions and so never got round to adding location based feeds. The good news for @gcoan and @PianSom is that I'm also in Bedfordshire (Potton) so the feed is (generally) appropriate for them. I have a friend in Suffolk who has seen one different PU to me, so it's not perfect, but without a better data source from OE there isn't much I can do. Not wishing to take this issue further off topic, if anyone has ideas on how to solve this please open an issue on this project and we can chat there.

gcoan commented 3 weeks ago

The good news for @gcoan and @PianSom is that I'm also in Bedfordshire (Potton) so the feed is (generally) appropriate for them.

Ha @8none1 amazing coincidence, I live in Wrestlingworth (which is the next village for those not local to East Bedfordshire)!

Pretty sure we will get identical power up events.

I've set the sensor up already and will test it next power up we get.

8none1 commented 3 weeks ago

I've wrangled the regexs and have what might be a JSON object listing future Free Electricity Sessions (FES).

As I mentioned, the style of the emails announcing FESs is a bit unpredictable, so it might take a little while to tweak the regex until such time as the wording on the emails is stable. I'll do what I can do keep it working, but I make no promises about it's reliability.

The JSON data is published here: https://www.whizzy.org/octopus_powerups/free_electricity_session.json

It's currently an empty list, because there are no future FES known.

If you want to see the gory details the GS script is here but you will need to get it set up in Google Apps Script yourself. Do note however, there is no need to run it yourself since FESs seem to be UK wide so the data source URL above, which is hosted on Github's infra and so should be highly available and fast, should work for everyone who has signed up to FES. Unlike Power Ups there is no need to also complete an opt-in form to benefit from the free power.

I haven't yet integrated this in to HA, but it will be essentially the same as detailed here. See the Home Assistant section on that post.

DragonQ commented 2 weeks ago

I just added a datetime helper and set that when I get an email notification of a free session the following day. I altered my automations to take advantage of the slots (charge battery less overnight, disable EV smart charging, manually charge EV & battery during session).

My biggest issue with the "free sessions" is that they show as planned/completed "dispatches" via the GraphQL API! This means HA (or anything else using the GraphQL API) thinks the free sessions are actually Intelligent Octopus slots, messing with price calculations! I am not sure if the API provides any differentiator between IO slots and free sessions or if this is even planned. Pretty stupid really.

DJBenson commented 1 week ago

Whilst you're waiting for a proper solution, I hacked something together using the IMAP integration if anybody wants a look. I've bundled it into a package file so aside from setting up the IMAP integration and copying and pasting the file/content to your homeassistant/packages folder there's nothing to it.

image

https://github.com/DJBenson/ha-stuff/blob/main/homeassistant/free_electricity.md

Edit: apologies I didn't see @8none1's solution as the thread was collapsed.

PianSom commented 1 week ago

Thanks @DJBenson - this is very useful.

However, for us lucky ones who also get Power-ups it would be even more useful to have an analogous email parser for those. I can confirm that the email format for them is stable - the opening paragraph with the event details has not changed since Sep last year.Here is the last notification, as an example.

Screenshot 2024-09-04 at 19 29 49

Would you be willing to create a Power-up fork?

gcoan commented 1 week ago

I've setup the @8none1 rest api calls for power up and free electricity sessions and they're working well.

Just need to write the automation to wrute my free period into the helper entities then I can call the 'write to predbat' script I already have working. And deal with when they both occur on the same day which caused me a minor glitch last time

PianSom commented 1 week ago

Thanks @gcoan - for some reason I seem to have stopped notifications on that repo and missed the responses

Gary-Manuel commented 4 days ago

I managed to scrape the value of the next Free Electricity session from the Octopus FAQs page directly into Home Assistant. The format is dreadful ("14th September 1-2pm") for converting into useful date/times but I'm sure it's doable.

image

RobinXe commented 4 days ago

Nice work @Gary-Manuel. Currently it seems like all the sessions are 1300-1400, so you probably only need to parse the date to get it working for now.

Gary-Manuel commented 4 days ago

May not even need to do that. If it changes, it's tomorrow (at 1 till 2).

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: RobinXe @.> Sent: Friday, September 13, 2024 5:40:49 PM To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Mention @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

Nice work @Gary-Manuelhttps://github.com/Gary-Manuel. Currently it seems like all the sessions are 1300-1400, so you probably only need to parse the date to get it working for now.

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2349373101, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBD33A2YTQW3PD5OOPCTZWMIRDAVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBZGM3TGMJQGE. You are receiving this because you were mentioned.Message ID: @.***>

RobinXe commented 4 days ago

Yeah, good point!

guy-BW commented 4 days ago

Here's a simple one-liner to get the next sessions details. Hopefully Octopus put this in the API.

curl -s https://octopus.energy/free-electricity/ | pup -c 'h3[data-block-key="fnrm2"] text{}'

Gary-Manuel commented 4 days ago

I tried to use the "fnrm2" data block key, but couldn't get scrape to select it, hence the complicated scrape criteria. I'm new to scraping and curling so I'll have a look at that.

Regardless of the method used, the remaining challenge is breaking the recovered string into separate / usable parts. I've managed to get Weekday, Date, Month and can assume Year is "2024". The tricky part is what to make of "1-2pm". I can split it into "1" and "2pm" easily enough but then what? What will 12 till 1 look like? What about 11:30am till 12:30pm? Future sessions might also be longer than 1 hour. Tricky. We need a proper API.

That's where BottlecapDave will step in to save the day (and my sanity) hopefully.

Gary-Manuel commented 4 days ago

Guy-BW. Liking the look of pup.


From: guy-BW @.> Sent: 14 September 2024 08:33 To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Mention @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

Here's a simple one-liner to get the next sessions details. Hopefully Octopus put this in the API.

curl -s https://octopus.energy/free-electricity/ | pup -c 'h3[data-block-key="fnrm2"] text{}'

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2350893760, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBD3R54R2QWVCU6DLIJDZWPRDTAVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJQHA4TGNZWGA. You are receiving this because you were mentioned.

gcoan commented 3 days ago

I'm using the https://github.com/8none1/octopus_powerups REST API mentioned earlier in this thread. Written a bit of Jinja scripting that decodes the REST output and stuffs it into HA helper entities (date, start time,end time) that I can then use in my own automations.

I have two REST API's and hence two slightly different scripts, one for the Free electricity events and one for the Power Up events.

Both working great.

Happy to share my script & dashboard if its of use to anyone else

BottlecapDave commented 3 days ago

When asked in the OE forums, it didn't sound like this would be added officially anytime soon. I plan to try and take a look at a solution as part of the integration, but using my own source as I don't want to piggy back off other people's solutions and potentially increase their demand. This should include

This might not make the next release, as that will be focusing on some saving session features and intelligent API changes.

Gary-Manuel commented 3 days ago

GCoan

Yes please.


From: Geoffrey Coan @.> Sent: 14 September 2024 19:08 To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Mention @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

I'm using the https://github.com/8none1/octopus_powerups REST API mentioned earlier in this thread. Written a bit of Jinja scripting that decodes the REST output and stuffs it into HA helper entities (date, start time,end time) that I can then use in my own automations.

I have two REST API's and hence two slightly different scripts, one for the Free electricity events and one for the Power Up events.

Both working great.

Happy to share my script & dashboard if its of use to anyone else

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2351087615, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBDZ5ZTBL25NV4ARW2LTZWR3QBAVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJRGA4DONRRGU. You are receiving this because you were mentioned.Message ID: @.***>

Gary-Manuel commented 3 days ago

BCD

That sound great. Hope your source uses a proper date format rather than the unformatted text that is used on the website. Some of the past events even have different format to the latest one.


From: David Kendall @.> Sent: 14 September 2024 20:26 To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Mention @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

When asked in the OE forums, it didn't sound like this would be added officially anytime soon. I plan to try and take a look at a solution as part of the integration, but using my own source as I don't want to piggy back off other people's solutions and potentially increase their demand. This should include

This might not make the next release, as that will be focusing on some saving session features and intelligent API changes.

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2351118276, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBD7SE74JMKH3YZXATRLZWSEU3AVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJRGEYTQMRXGY. You are receiving this because you were mentioned.

gcoan commented 3 days ago

Here's my solution:

  1. Three date time helpers, a date only octopus_power_up_date, and time only octopus_power_up_start_time and _end_time

  2. REST API calls to retrieve the times of the power up and free electricity events https://github.com/8none1/octopus_powerups These are setup in configuration.yaml to retrieve the times into HA sensors

  3. Scripts that decode the start/end date/times from the above HA sensors and write the REST API sensors into the 3 helper sensors

  4. A dashboard which shows the helper entities (and manually change them), write those sensors to predbat’s apps.yaml, see the REST API sensors (with the retrieved Octopus event details) and invoke the scripts that decode those sensors into the helper entities

Code:

  1. my configuration.yaml:
sensor: !include sensors.yaml

sensors.yaml:

  # Octopus Power up times
  - platform: rest
    name: "Octopus Power Up Times"
    unique_id: octopus_power_up_times
    resource: "https://www.whizzy.org/octopus_powerups/powerup.json"
    scan_interval: 900
    json_attributes_path: "$.[0]"
    json_attributes:
      - start
      - end

  # Octopus Free electricity times
  - platform: rest
    name: "Octopus Free Electricity Times"
    unique_id: octopus_free_electricity_times
    resource: "https://www.whizzy.org/octopus_powerups/free_electricity_session.json"
    scan_interval: 900
    json_attributes_path: "$.[0]"
    json_attributes:
      - start
      - end
  1. Script to retrieve the free electricity times from the REST API and write them into the 3 octopus power up helper entities. The REST API gets the Octopus date and time in UTC so have to convert to unix time and then back to local time in the right format to write to the helper time entities:
alias: Set Octopus Power Up helpers from free electricity REST sensor
sequence:
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.octopus_power_up_date
    data:
      date: >-
        {% set dt=state_attr('sensor.octopus_free_electricity_times','start') %}
        {% if dt != None %}
          {{ as_timestamp(dt)|timestamp_custom('%Y-%m-%d') }}
        {% endif %}
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.octopus_power_up_start_time
    data:
      time: >-
        {% set
        st_time=state_attr('sensor.octopus_free_electricity_times','start') %}
        {% if st_time != None %}
          {{ as_timestamp(st_time)|timestamp_custom('%X') }}
        {% endif %}
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.octopus_power_up_end_time
    data:
      time: >-
        {% set en_time=state_attr('sensor.octopus_free_electricity_times','end')
        %} {% if en_time != None %}
          {{ as_timestamp(en_time)|timestamp_custom('%X') }}
        {% endif %}
description: ""

3b Ditto script for Power up events:

alias: Set Octopus Power Up helpers from Power Up electricity REST sensor
sequence:
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.octopus_power_up_date
    data:
      date: >-
        {% set dt=state_attr('sensor.octopus_power_up_times','start') %} {% if
        dt != None %}
          {{ as_timestamp(dt)|timestamp_custom('%Y-%m-%d') }}
        {% endif %}
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.octopus_power_up_start_time
    data:
      time: >-
        {% set st_time=state_attr('sensor.octopus_power_up_times','start') %} {%
        if st_time != None %}
          {{ as_timestamp(st_time)|timestamp_custom('%X') }}
        {% endif %}
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.octopus_power_up_end_time
    data:
      time: >-
        {% set en_time=state_attr('sensor.octopus_power_up_times','end') %} {%
        if en_time != None %}
          {{ as_timestamp(en_time)|timestamp_custom('%X') }}
        {% endif %}
description: ""
  1. Dashboard card to pull all these bits together.
type: entities
entities:
  - entity: input_datetime.octopus_power_up_date
  - entity: input_datetime.octopus_power_up_start_time
  - entity: input_datetime.octopus_power_up_end_time
  - type: divider
  - entity: sensor.octopus_free_electricity_times
  - type: button
    icon: mdi:script-text-play-outline
    name: Set free electricity times
    action_name: Execute
    tap_action:
      action: perform-action
      perform_action: script.set_octopus_power_up_helpers_from_free_electricity_rest_sensor
  - type: divider
  - entity: sensor.octopus_power_up_times
  - type: button
    icon: mdi:script-text-play-outline
    name: Set Power Up electricity times
    action_name: Execute
    tap_action:
      action: perform-action
      perform_action: >-
        script.set_octopus_power_up_helpers_from_power_up_electricity_rest_sensor

Its basically a matter of clicking Execute on the Free electricity or Power up script which copies the rest data into the helper entities at the top of the screen and they can then be used by normal automations in HA

I do have an automation that detects when the REST API has retrieved new Octopus event details but this isn't working perfectly yet so I'll finish debugging it before sharing

Gary-Manuel commented 3 days ago

Thankyou


From: Geoffrey Coan @.> Sent: 15 September 2024 10:19 To: BottlecapDave/HomeAssistant-OctopusEnergy @.> Cc: Gary-Manuel @.>; Mention @.> Subject: Re: [BottlecapDave/HomeAssistant-OctopusEnergy] Octopus Free Electricity Sessions (Issue #973)

Here's my solution:

  1. Three date time helpers, a date only octopus_power_up_date, and time only octopus_power_up_start_time and _end_time

  2. REST API calls to retrieve the times of the power up and free electricity events https://github.com/8none1/octopus_powerups These are setup in configuration.yaml to retrieve the times into HA sensors

  3. Scripts that decode the start/end date/times from the above HA sensors and write the REST API sensors into the 3 helper sensors

  4. A dashboard which shows the helper entities (and manually change them), write those sensors to predbat’s apps.yaml, see the REST API sensors (with the retrieved Octopus event details) and invoke the scripts that decode those sensors into the helper entities

Code:

  1. my configuration.yaml:

sensor: !include sensors.yaml

sensors.yaml:

Octopus Power up times

alias: Set Octopus Power Up helpers from free electricity REST sensor sequence:

3b Ditto script for Power up events:

alias: Set Octopus Power Up helpers from Power Up electricity REST sensor sequence:

type: entities entities:

Its basically a matter of clicking Execute on the Free electricity or Power up script which copies the rest data into the helper entities at the top of the screen and they can then be used by normal automations in HA

I do have an automation that detects when the REST API has retrieved new Octopus event details but this isn't working perfectly yet so I'll finish debugging it before sharing

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/973#issuecomment-2351487500, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN7SBD2RU3XPA433GATYMK3ZWVGJLAVCNFSM6AAAAABMQD6SSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJRGQ4DONJQGA. You are receiving this because you were mentioned.Message ID: @.***>

gcoan commented 18 hours ago

Final bit of the power-up/free electricity jigsaw, an automation that detects when there is a new power up or free electricity event (as registered by the REST sensor) and raises an alert.

Could quite easily automate this to invoke the scripts to decode the REST response and update the helper date/time entities (and make any other automations you want), but I'd prefer to be a bit more in control. Amend the URL in the automation to the pathname of the Powerup dashboard so clicking on the notification results in the correct dashboard page being opened.

  1. Automation:
alias: Octopus New Power up Alert
description: Alert when new Octopus Power up or Free Electricity period
trigger:
  - platform: state
    entity_id:
      - sensor.octopus_free_electricity_times
    from: "[{\"start\":null,\"end\":null}]"
    variables:
      alert_text: New Free Electricity times
  - platform: state
    entity_id:
      - sensor.octopus_power_up_times
    from: "[{\"start\":null,\"end\":null}]"
    variables:
      alert_text: New Power up electricity times
action:
  - action: notify.all_devices
    data:
      title: Octopus Electricity session
      message: |
        {{ now().timestamp() | timestamp_custom('%-d %b %H:%M') }} INFO: {{ alert_text }}
      data:
        visibility: public
        persistent: true
        url: /dashboard-givenergy/powerup
        push:
          sound:
            name: default
            critical: 0
            volume: 0.8
mode: single
8none1 commented 18 hours ago

I wrote up how I'm triggering automations in this post: https://www.whizzy.org/2024-09-14-free-electricity-sessions/

gcoan commented 17 hours ago

I wrote up how I'm triggering automations in this post: https://www.whizzy.org/2024-09-14-free-electricity-sessions/

A nice clear writeup of how to configure the rest API and a 'session active' binary sensor. My use case uses the first bit of your solution but I want to know in advance the date and time of the sessions as I need to program them into Predbat which manages my battery & solar inverter activity. Predbat decides (and executes) whether to discharge my battery ahead of the session and then charge up in the session or not. If the sessions coincide with a sunny day then often its not worth discharging as I'll be generating more solar than I can charge into the battery, so its better to just export the excess. Cloudy windy days, it can be worthwhile.

The API is working great and with my scripts and automations I have a great way to feed this into HA and Predbat