Announcement

Collapse
No announcement yet.

Simple web request to pull Octopus Energy rates not working.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jon00
    replied
    Originally posted by manaesh View Post
    Thanks Jon

    I will take a look at that and try and get my head round it - JSON is a new area for me....

    Then i need to work out how to get the cost per hour from my Currentcost for both rates....

    INteresting excerise!

    Cheers

    Mike
    I've made it very easy to parse JSON. Full details in the docs.

    Leave a comment:


  • manaesh
    replied
    Thanks Jon

    I will take a look at that and try and get my head round it - JSON is a new area for me....

    Then i need to work out how to get the cost per hour from my Currentcost for both rates....

    INteresting excerise!

    Cheers

    Mike

    Leave a comment:


  • jon00
    replied
    Originally posted by manaesh View Post
    Thanks Chris - will take a look at Node-Red.

    I have got Jon00s script working and putting the data into the log....

    Stupid question - but how do i get to write that to a device? Its been a while (10 years) since i dabbled in scripting, and that was in HS2!

    Thanks anyone for any help!

    Cheers

    Mike
    It may be easier if you use my datascraper script which parses JSON and creates devices for you.

    Leave a comment:


  • manaesh
    replied
    Thanks Chris - will take a look at Node-Red.

    I have got Jon00s script working and putting the data into the log....

    Stupid question - but how do i get to write that to a device? Its been a while (10 years) since i dabbled in scripting, and that was in HS2!

    Thanks anyone for any help!

    Cheers

    Mike

    Leave a comment:


  • chrisgla
    replied
    As an option, there’s a flow to pull the data into Node-Red:- https://discourse.nodered.org/t/best...ost-array/7929

    I tried Homeseer scripts and got one working, but my limited programming skills wouldn’t have been up to keeping it up to date or debugging. From Node-Red I then just use mcsMQTT to bring in the current rate or other data as needed to Homeseer. Node-Red also feeds influxdb/ Grafana directly avoiding loading up H9meseer with this task.

    Leave a comment:


  • manaesh
    replied
    Hi Ecuboss

    I am trying to accomplish the same solution as you. Would you mind sharing your scripts/advice on how you got your solution working?

    I already have my power via currentcost, and the device history plugin.

    Due to migrate to Agile Octopus in 2 weeks time!

    Cheers

    Mike

    Leave a comment:


  • chrisgla
    replied
    Received my Hildebrand IHD+CAD on Monday, few teething problems but I'm now getting live consumption data from Smart meter.
    Hildebrand API detail here:- https://docs.glowmarkt.com/Glowmarkt...rForBright.pdf
    And examples/ more docs here:- https://bitbucket.org/ijosh/brightglowmarkt/src/master/

    The TOU rates aren't coming across from Octopus in the meter data as yet- just the previous set tariff. Unsure if others are getting this data in their IHD?

    Going through a steep learning curve with Postman!

    Leave a comment:


  • chrisgla
    replied
    Did you manage to get Octopus Agile rate import fully working, and if so could you share script?
    It's years since I've done any scripting so I'd started to import individual half hourly rates to devices using Big5- it seems slightly easier but may be just as much learning by the time I add the logic and calculations.

    I want to use the rates to work out cheapest time to charge for car and possibly set charge rate as well.
    Ideally, knowing battery capacity (set value) and state % (from Teslaseer) to get kWh needed, divide by 7kW and then identify half hourly charge slots.

    Ambitious

    I have some other load I plan to shed during the 4-8pm peak rate (also looked at battery but too expensive and bureaucratic for now)

    There's an interesting example in the Octopus Agile API reference of how to get the lowest rate on day- I need to figure out how to get the "x" minimum half hourly slot rates:-

    $ http $TARIFF_URL/standard-unit-rates/ \
    period_from=="2018-05-16T00:00" period_to=="2018-05-17T00:00" | \ jq '.results| min_by('.value_inc_vat')' { "value_exc_vat": 7.2, "value_inc_vat": 7.56, "valid_from": "2018-05-16T04:30:00Z", "valid_to": "2018-05-16T05:00:00Z" }

    Particularly with many of us being stuck at home during the day Agile rates make a significant difference.

    I also have a Hildebrand Glowstick CAD + HAN on the way that should give real time data using the Smart Meter Zigbee interface via MQTT or Modbus.

    I don't know how many are interested in the UK, I'd be happy to put towards a bounty to get a proper PI or script as I think a few of us in UK would benefit...

    Leave a comment:


  • ecuboss
    replied

    As a follow-up - here's what I wanted to do.
    Octopus energy in the UK have a "time of day" pricing scheme, where it's generally lower than a flat rate by increases massively in the early evening to discourage peak usage.
    As we cook with electricity and typically around 5pm, I wanted to see what the impact would be compared to having cheaper electricity elsewhere.
    • Yellow line is live consumption in Kw
    • The blue line represents how much I spent in 24 hours on flat rate electricity (13p a Kwh)
    • The red line against Y2 axis is the pence per Kwh for Octopus - as you can see, it varies between 5p and 25p.
    • The green line is what I would of spent if I was using the Octopus [varied] rate. You can see I save money, then it catches up in the evening but never overtakes the flat rate.


    I used a TLS257 photodiode connected to a NodeMCU board the Enigmatheatre Arduino Plugin in API mode to pulse count the usage of my electricity meter
    Scripts to pull in the rates and bring the pulses in and update virtual devices with consumption
    and the "Device History" plugin for the graphs.


    Attached Files

    Leave a comment:


  • ecuboss
    replied
    Thanks - that seems to be pulling the rates in nicely thanks.

    Leave a comment:


  • jon00
    replied
    You can use a quick and dirty method to get JSON data:

    Code:
    Imports System.Web.Script.Serialization
    
     Public Sub Main(ByVal Parms As Object)
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
    
            Dim Period_from As String
            Period_from = (System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"))
            Dim Period_to As String
            Dim response As String = ""
    
    
    
            Period_to = (System.DateTime.UtcNow.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:ssK"))
            Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=" & Period_from & "&period_to=" & Period_to
            'Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=2020-02-06T20:30:00Z&period_to=2020-02-06T22:35:00Z"
    
            hs.WriteLog("url:", requestUrl)
    
            response = hs.URLAction(requestUrl, "GET", "", "Content-Type: application/json")
            Dim json As New JavaScriptSerializer
            hs.WriteLog("reply:", response)
    
            Try
    
               Dim dataObj As Object = json.Deserialize(Of Object)(response)
    
               hs.WriteLog("response:", dataObj("results")(0)("value_exc_vat").ToString)
               hs.WriteLog("response:", dataObj("results")(0)("value_inc_vat").ToString)
               hs.WriteLog("response:", dataObj("results")(0)("valid_from").ToString)
               hs.WriteLog("response:", dataObj("results")(0)("valid_to").ToString)
               hs.WriteLog("response:", dataObj("count").ToString)
    
    
            Catch ex As Exception : hs.WriteLog("Test Script", "Error:  " & ex.Message.ToString)
            End Try
    
        End Sub

    Leave a comment:


  • ecuboss
    replied
    So i've spent loads more time and feel close but no cigar,
    I can extract from the first level, such as obj.count - but
    I cant extract the
    value_inc_vat from the results subsection.

    I've got it working with tenscripting as well now and i can see the data is at my fingertips:

    Click image for larger version

Name:	octopus.PNG
Views:	501
Size:	184.8 KB
ID:	1363113

    Code:
    Imports System.Web.Script.Serialization
    
     Public Sub Main(ByVal Parms As Object)
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
    
            Dim Period_from As String
            Period_from = (System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"))
            Dim Period_to As String
            Dim response As String = ""
    
    
    
            Period_to = (System.DateTime.UtcNow.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:ssK"))
            Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=" & Period_from & "&period_to=" & Period_to
            'Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=2020-02-06T20:30:00Z&period_to=2020-02-06T22:35:00Z"
    
            hs.WriteLog("url:", requestUrl)
    
            response = hs.URLAction(requestUrl, "GET", "", "Content-Type: application/json")
            Dim json As New JavaScriptSerializer
            hs.WriteLog("reply:", response)
    
            Try
                Dim dataObj As jsonStructure = json.Deserialize(Of jsonStructure)(response)
    
    
    
                hs.WriteLog("response:", dataObj.results.value_exc_vat.ToString)
    
    
            Catch ex As Exception : hs.WriteLog("Test Script", "Error:  " & ex.Message.ToString)
            End Try
    
        End Sub
    
    
        Public Class jsonStructure
            Public Property count As Integer
            Public Property _next As Object
            Public Property previous As Object
            Public Property results() As Result
        End Class
    
        Public Class Result
            Public Property value_exc_vat As Single
            Public Property value_inc_vat As Single
            Public Property valid_from As Date
            Public Property valid_to As Date
        End Class

    Leave a comment:


  • jon00
    replied
    It's a json response so you would need to deserialize.

    Example here:

    https://forums.homeseer.com/forum/de...450#post910450

    You can also use my datascraper script which you can extract the data though regex and show on a virtual device without any coding.

    Leave a comment:


  • ecuboss
    replied
    Yes it does work - been stuck on that all morning, Many thanks.

    Any tips on how i can extract the "value_inc_vat" value from the response?

    Leave a comment:


  • jon00
    replied

    See if this works:

    Code:
    Imports System.Net    
    
    Public Sub Main(ByVal Parms As Object)
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
        Dim response As String = ""
        Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=2020-02-06T22:30:00Z&period_to=2020-02-06T22:35:00Z"  '
        response = hs.URLAction(requestUrl, "GET", "", "Content-Type: application/json")
        hs.WriteLog("response:", response)
    
        End Sub

    Leave a comment:

Working...
X