+ Antworten
Seite 2 von 3 ErsteErste 1 2 3 LetzteLetzte
Ergebnis 11 bis 20 von 23
  1. #11
    Registriert seit
    Sep 2017
    Ort
    Tromsø, Norway
    Beiträge
    29

    Hi and happy new year,

    No I have not been able to figure out the websocket yet. I will just try to buy some "premium support" at Symcon and see if they can help me setting up a websocket.

    As it is now I'm getting the current last hour energy price with this code and writing it to a variable:

    PHP-Code:
    $json '{"query":"{viewer {homes {currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}"}';

    # Create a connection
    $ch curl_init('https://api.tibber.com/v1-beta/gql');
    # Setting our options
    curl_setopt($chCURLOPT_URL'https://api.tibber.com/v1-beta/gql');
    curl_setopt($chCURLOPT_HTTPHEADER
       array(
    'Content-Type: application/json',  
       
    'Authorization: Bearer 41121d0cdb9d4d2592c2c0c3395add82166e9e3a160d6abf0b70cd8******')); 
    curl_setopt($chCURLOPT_POSTtrue);
    curl_setopt($chCURLOPT_POSTFIELDS$json);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    # Get the response
    $response curl_exec($ch);
    curl_close($ch);

    //Decoding of the JSON data
    $data json_decode($response); 
    $current $data->data->viewer->homes[0]; 

    $total $current->currentSubscription->priceInfo->current->total
    //var_dump($total); 

    //Convert KR to Øre
    $pris floatval($total) * floatval(100);

    //Write Energy price Incl Tax to Float 
    setvalue  (35230$pris) ; 

    What I want to try now is to get the whole 24 hour day price in one query and get this into a variable for a nice graph so I can adjust my power consumption after this.
    According to Tibber I just change my query by changing "current" to "today":
    PHP-Code:
    $json '{"query":"{viewer {homes {currentSubscription {priceInfo {today {total energy tax startsAt }}}}}}"}'
    But I am not able to get the data in the same way in the code.
    When I try it in the Tibber API explorer I get:
    HTML-Code:
    {
      "data": {
        "viewer": {
          "homes": [
            {
              "currentSubscription": {
                "priceInfo": {
                  "today": [
                    {
                      "total": 0.2319,
                      "energy": 0.22,
                      "tax": 0.0119,
                      "startsAt": "2020-01-14T00:00:00+01:00"
                    },
                    {
                      "total": 0.1957,
                      "energy": 0.1838,
                      "tax": 0.0119,
                      "startsAt": "2020-01-14T01:00:00+01:00"
                    },
                    {
                      "total": 0.1941,
                      "energy": 0.1822,
                      "tax": 0.0119,
                      "startsAt": "2020-01-14T02:00:00+01:00"
                    },
    Here I get the price for every hour.
    I see there is an [ before and after all the data. Is this an array?

    Could anyone please assist in how I can change my script to be able to decode the data and write it to a variable so I can display the whole 24Hour energy price?

  2. #12
    Registriert seit
    Oct 2011
    Ort
    Hattersheim (Hessen)
    Beiträge
    6,868

    Zitat Zitat von dreeas Beitrag anzeigen
    Here I get the price for every hour.
    I see there is an [ before and after all the data. Is this an array?
    Yes this is an array you get multiple values per day.

    PHP-Code:
    $prices_today $data->data->viewer->homes[0]->currentSubscription->priceInfo->today;
    foreach(
    $prices_today as $price)
    {
        
    var_dump($price);

    Zitat Zitat von dreeas Beitrag anzeigen
    Could anyone please assist in how I can change my script to be able to decode the data and write it to a variable so I can display the whole 24Hour energy price?
    What do you want to do exactly, there are several values, do you want a special value e.g. looking for the lowest or do you want to write each value individually in a separate variable?
    how to write the 24 values in a single variable so that the archive also records them over the last 24 hours, I am questioned myself, maybe this can answer IP-Symcon or someone else who has done this before.

  3. #13
    Registriert seit
    Sep 2017
    Ort
    Tromsø, Norway
    Beiträge
    29

    Thank you Fonzo.
    Now I believe I can write all 24 values to its own variable :-)

    But then the problem is exactly as you mention, how can I write these 24 variables to one with different timestamps to generate a 24 hour trend over the energy price?

  4. #14
    Registriert seit
    Oct 2011
    Ort
    Hattersheim (Hessen)
    Beiträge
    6,868

    Zitat Zitat von dreeas Beitrag anzeigen
    Now I believe I can write all 24 values to its own variable :-)

    But then the problem is exactly as you mention, how can I write these 24 variables to one with different timestamps to generate a 24 hour trend over the energy price?
    If you want to write this to one variable you have to add this to the archive. So you need three variables, total, energy, tax and activate archive setting. Then you need a script that runs exactly every 24 hours with a cyclic event in IP-Symcon.

    The skript should be as followed:
    PHP-Code:
    $json '{"query":"{viewer {homes {currentSubscription {priceInfo {today {total energy tax startsAt }}}}}}"}'
    $response SendCommand($json);
    function 
    SendCommand($json)
    {
        
    # Create a connection
    $ch curl_init('https://api.tibber.com/v1-beta/gql');
    # Setting our options
    curl_setopt($chCURLOPT_URL'https://api.tibber.com/v1-beta/gql');
    curl_setopt($chCURLOPT_HTTPHEADER
       array(
    'Content-Type: application/json',  
       
    'Authorization: Bearer d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a')); // Demo token
    curl_setopt($chCURLOPT_POSTtrue);
    curl_setopt($chCURLOPT_POSTFIELDS$json);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    # Get the response
    $response curl_exec($ch);
    curl_close($ch);
        return 
    $response;
    }

    $data json_decode($response);
    $prices_today $data->data->viewer->homes[0]->currentSubscription->priceInfo->today;

        
    $total_arr = [];
        
    $energy_arr = [];
        
    $tax_arr = [];
    foreach(
    $prices_today as $key => $price)
    {
        
    $timestamp strtotime($price->startsAt);
        
    $total $price->total;
        
    $energy $price->energy;
        
    $tax $price->tax;
        
    $total_arr[$key] = [
            
    'TimeStamp' => $timestamp,
            
    'Value' => $total
        
    ];
        
    $energy_arr[$key] = [
            
    'TimeStamp' => $timestamp,
            
    'Value' => $energy
            
    ];
        
    $tax_arr[$key] = [
            
    'TimeStamp' => $timestamp,
            
    'Value' => $tax
            
    ];
    }
    $archive_id 11380;
    $total_id 21856;
    $energy_id 19802;
    $tax_id 40813;

    AddArchiveValues($archive_id$total_id$total_arr);
    AddArchiveValues($archive_id$energy_id$energy_arr);
    AddArchiveValues($archive_id$tax_id$tax_arr);

    function 
    AddArchiveValues($archive_id$variable_id$values_array)
    {
    AC_AddLoggedValues($archive_id$variable_id$values_array);
    AC_ReAggregateVariable($archive_id$variable_id);

    .

  5. #15
    Registriert seit
    Sep 2017
    Ort
    Tromsø, Norway
    Beiträge
    29

    Learning alot here now, great.

    Now the script stops at:
    PHP-Code:
    AC_AddLoggedValues($archive_id$variable_id$values_array); 
    With the message:
    Warning: Cannot add data with timestamps after logged data that is not yet written to file in /var/lib/symcon/scripts/13063.ips.php on line 49

    $archive_id I set to my archive and $total_id is a new variable.
    The "tax" and the "energy" I actually don't need as this "Total" is the sum of these.

  6. #16
    Registriert seit
    Feb 2017
    Beiträge
    1,539

    According to the message, you try to add values that occur before data that is not yet written to the file, i.e., the newest data, up to a couple of minutes old. To keep consitency, this is blocked. Maybe you want to write the data for 0:00 at 0:00? In such a case, you could either wait and add the values at 0:05 instead or you could just use SetValue.

  7. #17
    Registriert seit
    Oct 2011
    Ort
    Hattersheim (Hessen)
    Beiträge
    6,868

    Zitat Zitat von dreeas Beitrag anzeigen
    With the message:
    Warning: Cannot add data with timestamps after logged data that is not yet written to file in /var/lib/symcon/scripts/13063.ips.php on line 49
    Have you run the script multiple times in the past 24 hours? What is the current number of measurements in the archive?
    Otherwise, you would have to add a query that first checks whether the last timestamp is older than the data that you want to add in case the script is accidentally executed more than every 24 hours.

  8. #18
    Registriert seit
    Sep 2017
    Ort
    Tromsø, Norway
    Beiträge
    29

    Not sure I follow you guys exactly.

    PHP-Code:
       $total_arr[$key] = [
            
    'TimeStamp' => $timestamp,
            
    'Value' => $total
        
    ];
    }
     
    var_dump($total_arr); 
    Doing the vardump above I get 24 arrays of:
    HTML-Code:
     [0]=>
      array(2) {
        ["TimeStamp"]=>
        int(1579042800)
        ["Value"]=>
        float(0,2021)
    This is the energy price from 00:00 - 01:00 at night.
    I see the unix timestamp translates to 23:00 - 00:00 as I guess this is UTC time.
    The string value for the same array was:
    string(25) "2020-01-15T00:00:00+01:00".
    So I guess that is one hour wrong.

    Just to conclude what I want to do. Just after midnight every day I want to get the upcoming 24 hour energy price and write to a variable and display the trend. So I can adjust my power consumption after the price that day. So yes the timestamps will be up to 24 hours into the future

    When running the below script it does not write any values at all to the $total_id variable.
    It just gives the error mentioned in my previous post.

    PHP-Code:
    <?php

    $json 
    '{"query":"{viewer {homes {currentSubscription {priceInfo {today {total energy tax startsAt }}}}}}"}'
    $response SendCommand($json);
    function 
    SendCommand($json)
    {
        
    # Create a connection
    $ch curl_init('https://api.tibber.com/v1-beta/gql');
    # Setting our options
    curl_setopt($chCURLOPT_URL'https://api.tibber.com/v1-beta/gql');
    curl_setopt($chCURLOPT_HTTPHEADER
       array(
    'Content-Type: application/json',  
       
    'Authorization: Bearer 41121d0cdb9d4d2592c2c0c3395add82166e9e3a160d6abf0b70cd85efb2****')); // Demo token
    curl_setopt($chCURLOPT_POSTtrue);
    curl_setopt($chCURLOPT_POSTFIELDS$json);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    # Get the response
    $response curl_exec($ch);
    curl_close($ch);
        return 
    $response;
    }

    $data json_decode($response);
    $prices_today $data->data->viewer->homes[0]->currentSubscription->priceInfo->today;
    //var_dump($prices_today);

        
    $total_arr = [];

    foreach(
    $prices_today as $key => $price)
    {
        
    $timestamp strtotime($price->startsAt);
        
    $total $price->total;

        
    $total_arr[$key] = [
            
    'TimeStamp' => $timestamp,
            
    'Value' => $total
        
    ];
    }
     
    //var_dump($total_arr);

    $archive_id 30456;
    $total_id 26429;

    AddArchiveValues($archive_id$total_id$total_arr);

    function 
    AddArchiveValues($archive_id$variable_id$values_array)
    {
    AC_AddLoggedValues($archive_id$variable_id$values_array);
    AC_ReAggregateVariable($archive_id$variable_id);
    }

  9. #19
    Registriert seit
    Sep 2017
    Ort
    Tromsø, Norway
    Beiträge
    29

    I did a test with the command AC_AddLoggedValues and could add data with timestamp in the past just fine, but if I try to add data forward in time I get the same error message.

    Is it not possible to enter future data in the archive?

  10. #20
    Registriert seit
    Feb 2017
    Beiträge
    1,539

    You are correct, adding future data is not possible. You could write the future data into a String variable as array, extract the current value at every full hour and write it into your variable.Thus, you would add the trend over the day.

Ähnliche Themen

  1. SMA Energy Meter
    Von rene im Forum Allgemeine Diskussion (2.x/3.x)
    Antworten: 73
    Letzter Beitrag: 06.01.20, 21:15
  2. Gubino 3 phasen smart meter
    Von spx im Forum Z-Wave
    Antworten: 22
    Letzter Beitrag: 07.12.19, 16:12
  3. Smart Meter - Discovergy Erfahrungen?
    Von Hollowman im Forum Off Topic
    Antworten: 6
    Letzter Beitrag: 29.04.19, 10:05
  4. B-Control Smart Meter
    Von jgoller im Forum Haustechnik
    Antworten: 2
    Letzter Beitrag: 06.07.16, 11:53
  5. Aeon Labs Home Energy Meter
    Von Marko im Forum Z-Wave
    Antworten: 4
    Letzter Beitrag: 17.01.13, 14:55