Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Energi Panel - Panel Settings - Tariff


JcBorgs

Recommended Posts

This is of some use perhaps…. but not if you have a tariff that charges on a hourly basis.

 

Is it possible to set the tariff via LUA code?

 

I get the cost/kWh from my energy company and have a QA for it that updates this on an hourly basis, would be ideal if it was possible to take that value and put in the Energy Panel Setting for Tariff.

 

 

Link to comment
Share on other sites

Changing main tariff every hour will do the job just fine.

 

You will find the request on Swagger or you can sniff the request on devtools in the browser.

Link to comment
Share on other sites

  • Topic Author
  • 9 minutes ago, m.roszak said:

    Changing main tariff every hour will do the job just fine.

     

    You will find the request on Swagger or you can sniff the request on devtools in the browser.

    @m.roszak

    Ok…. that sound simple….not….. :-)

    Changing the main tariff every hour is exactly what I want to do, but… would appreciate some guidance as I don’t know how to find this on Swagger and don’t have access to any devtools….

     

    So want to do this via LUA, with a scene that runs every hour and put’s the cost I get from the energy company in the QA and put that value in the Tariff on the energy panel setting.

    Link to comment
    Share on other sites

    Request body (in json):


     

    Please login or register to see this code.


    as Lua table:

     

    Please login or register to see this code.

     

    Just put in "rate" the value for 1 kWh in your currency :)

    I have quicky tested this in build-in swagger and all works as supposed:


    Please login or register to see this attachment.



     

    Link to comment
    Share on other sites

  • Topic Author
  • 21 minutes ago, m.roszak said:

    Request body (in json):


     

    Please login or register to see this code.


    as Lua table:

     

    Please login or register to see this code.

     

    Just put in "rate" the value for 1 kWh in your currency :)

    I have quicky tested this in build-in swagger and all works as supposed:


    Please login or register to see this attachment.



     

    Highly appreciated for the guidance @m.roszak

     

    Will dig into this and hopefully be able to create a simple scene that handles this.

    Link to comment
    Share on other sites

  • Topic Author
  • @m.roszak

    Need some more help on this…… haven’t worked with either swagger or api commands i the past and are a bit lost.

     

    Did the following simple scene that runs every hour. Doesn’t give any error code but doesn’t do anything either.

    The 945 unit is a QA for the energy company and the value if that is the current cost/kWh, the value are stored in a 0.00 format

     

    Rather sure that I have made some errors in the api.put command but have no clue what to change.

     

    local kWhPrice = hub.getValue(945"value")
    api.put("/energy/billing/tariff", {name = "Main", rate = kWhPrice, returnRate = 100, additionalTariffs = {} })
     
     
     
    Have also tried a simple api.get("/energy/billing/tariff") just to see if I could get the Tariff data but the data returned are strange….
     
    local TariffData = api.get("/energy/billing/tariff")
    hub.debug("Scene548""Tariff is now", TariffData, "!!")


    which gives the following output in the log:

    [17.04.2022] [12:35:23] [DEBUG] [SCENE548]: Tariff is now table: 0xffffac08dab0

    [17.04.2022] [12:35:25] [DEBUG] [SCENE548]: Tariff is now table: 0x13108a10

    [17.04.2022] [12:35:28] [DEBUG] [SCENE548]: Tariff is now table: 0xffff24001be0

    [17.04.2022] [12:35:31] [DEBUG] [SCENE548]: Tariff is now table: 0xffff20154200

     
     
     
    Link to comment
    Share on other sites

  • Topic Author
  • api.get “issue" solved, just a matter of reading out the data from the api.get in the correct manner. So that part now works and gets the correct data out.

     

    local TariffData = api.get("/energy/billing/tariff")
    local TFcost = (TariffData.rate)
    hub.debug("Scene548""Tariff is now", TFcost)

     

    [17.04.2022] [13:04:17] [DEBUG] [SCENE548]: Tariff is now 0.78

    [17.04.2022] [13:04:18] [DEBUG] [SCENE548]: Tariff is now 0.78

    [17.04.2022] [13:04:19] [DEBUG] [SCENE548]: Tariff is now 0.78

     

     

    But what is missing in my api.put command to get it to work?

    local kWhPrice = hub.getValue(945"value")
    api.put("/energy/billing/tariff", {name = "Main", rate = kWhPrice, returnRate = 100, additionalTariffs = {} })
     
    As previously stated it doesn’t give any error codes when the scene is executed. but it does not change anything either, so something are apparently lacking…..

     

    Link to comment
    Share on other sites

  • Topic Author
  • In the Energy Panel Settings the Tariff value is put to 0.64 before the code is executed

     

    Current code in testning:

    --Define data to put

    local TariffData = {
      name = "Main",
      rate = 0.73,
      returnRate = 100,
      additionalTariffs = {}
    }
    --print ”rate” value to ensure it is formated correctly
    print("Tariffdata:", TariffData.rate)
     
    --Convert Data to JSON format
    local TariffDataJSON = json.encode(TariffData)
    --Print JSON format of data
    print("JSON Format:", TariffDataJSON)
     
    --api put data to /energy/billing/tariff
    --trying a couple of different format
    api.put("/energy/billing/tariff",TariffDataJSON)
    api.put("/energy/billing/tariff",{TariffDataJSON})
    api.put("/energy/billing/tariff",TariffData)
    api.put("/energy/billing/tariff",{TariffData})
     
    --api get data from /energy/billing/tariff
    local TariffGETdata = api.get("/energy/billing/tariff")
    --print data gotten with api.get
    print("Tariff rate is:", TariffGETdata.rate)
    print("---------------------------------")
     
    Gives the following output in the Logg:
    [17.04.2022] [17:50:19] [DEBUG] [SCENE548]: Tariffdata: 0.73
    [17.04.2022] [17:50:19] [DEBUG] [SCENE548]: JSON Format: {"returnRate":100,"name":"Main","additionalTariffs":[],"rate":0.73}
    [17.04.2022] [17:50:19] [DEBUG] [SCENE548]: Tariff rate is: 0.64
    [17.04.2022] [17:50:19] [DEBUG] [SCENE548]: ---------------------------------
     
    So the api.get part is working as it should and collects the correct data.
     
    But what is wrong with the api.put part of the code? I know there is only need for 1 api.put command but have four today to experiment with different formats. But feels like there is something missing from the code as the data provided isn’t written as it should be.
     
    Anyone have any good tips what I am missing????
     
     
    Link to comment
    Share on other sites

    As for api.put in scenes, there is an issue with additionalTarrifs field as lib does not know if this is an object or array - because of that it does not work.

    With some adjustments you can use similar code in QuickApp directly:


     

    Please login or register to see this code.


    If you want to use the scene classic http request (not api.put) will be needed.

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, m.roszak said:

    As for api.put in scenes, there is an issue with additionalTarrifs field as lib does not know if this is an object or array - because of that it does not work.

    With some adjustments you can use similar code in QuickApp directly:


     

    Please login or register to see this code.


    If you want to use the scene classic http request (not api.put) will be needed.

    @m.roszak Yes I notice that as well, together with @cag014 I managed to solve it in a scene.. 

     

    There are two ways, probably the best is what @cag014 came up with:

    Please login or register to see this code.

    Where your first read the existing data, then modifies it with a new value and then writes it back again.

     

    There are also the method that I found to specify it with an additionalTariff>

    local TariffData = {
      rate = 0.99,
      name = "Main",
      returnRate = 100,
      additionalTariffs= {
        {rate = 0.99,
          name = "Main2",
          startTime = "00:00",
          endTime = "00:00",
          days = {
            "monday"
          }
        }
      }
    }
     
    But that has the drawback that you get an Additional Tariff regardless if you want it or not, so definitely think that @cag014 solution is better…
     
     
    • Like 1
    • Thanks 1
    Link to comment
    Share on other sites

    • 2 weeks later...

    @JcBorgs
    Do you have the final scene and can share it?
    Tryed what was shared in the Tibber tread, but can`t see that I got it working. Was that the whole code?

    Was fetching the price from the Tibber QA - Current price.

    Link to comment
    Share on other sites

  • Topic Author
  • 15 hours ago, dorten75 said:

    @JcBorgs
    Do you have the final scene and can share it?
    Tryed what was shared in the Tibber tread, but can`t see that I got it working. Was that the whole code?

    Was fetching the price from the Tibber QA - Current price.

    Sure, this is the code I use:

     

    Declaration part: (This makes the scene run once every hour on minute 02 of the hour)

    Please login or register to see this code.

    Actions part:

    Please login or register to see this code.

     

    • Like 1
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...