Created At

Nov 29, 2017

Last Update

Dec 17, 2018

Platforms

HC 2

Views

433

Download

15

Current status: Pre-release

Next steps: Get user feedback and improve

Need help or want to contribute?: help@tibber.com

How to

To enable price updates from Tibber you will need to download and import the virtual device which will hold the current price. You will also create a scene which is responsible for fetching the price and update you virtual device.

1. Go to tibber api login and retreive your access token. If you dont have a tibber account you can use demo token to test this.

https://developer.tibber.com/settings/accesstoken

2. Download the virtual device and import it. Optionally update icon. Retreive the deviceId, you will need it in step 3.

3. Create the LUA scene and call it I.e "Tibber scene". Add the code which is at the bottom of this post. Update the field where token is required. Update the DeviceId fields.

4. Now that your scene is setup you will have to update your device with the scene id.

 

Extended help:

The scene id is visible under: Scenes/Scene name/ general tab

The device id can be found using the local fibaro api i.e: http://192.168.0.0/api/devices

 

 

 

LUA script for scene:

local http = net.HTTPClient();

local payload = '{"query": "{viewer {homes {currentSubscription {priceInfo {current {total currency}}}}}}", "variables": null, "operationName": null}';

 

http : request('https://api.tibber.com/v1-beta/gql',  {

    options = {

        method = "POST",

        headers = {

            ['Authorization'] = 'Bearer YOUR_UNIQUE_TOKEN_HERE',

            ['Content-Type'] = 'application/json'

        

      },

      data = payload

    },

    success = function(response) 

      fibaro:debug (response.data)      

      local startIndex = string.find(response.data,'{"total":') + 9;

      local endIndex = string.find(response.data,',')-1;

      local price = string.sub(response.data,startIndex, endIndex);    

      startIndex = string.find(response.data,'currency":"') + 11;

      endIndex = string.find(response.data,'}')-2;

      local currency = string.sub(response.data,startIndex, endIndex);

      fibaro:debug(price)

      fibaro:debug(currency)

      fibaro:call(DEVICE_ID, 'setProperty', 'ui.Price.value', price);

      fibaro:call(DEVICE_ID, 'setProperty', 'ui.TibberPrice.value', price..' '..currency);  

    end,

         error = function(err) fibaro:debug ("Error:" .. err)

    end

});

 

 

4 Comments,  Want to add comment please login
388239864606da0544ab5d36b40671db

Need to edit Main Loop to get VD to run automaticly. e.g: local lastModified = fibaro:getModificationTime(DEVICE ID, 'ui.Timestamp.value'); if ((os.time()) - tonumber(lastModified) >= 1800) then fibaro:startScene(SCENE ID); local time =os.date ("%c"); fibaro:debug(time); fibaro:call(DEVICE ID, 'setProperty', 'ui.Timestamp.value', time) else end

C3f08dc31901d127bfd47631102f4751

Same problem to me, the Scene dosen't run automaticly. It update the price if I run it manually.

05651aa7ac0eede16b876f7139d20e01

The VD does not update automaticly. If i run the scene it seems to work, but is that the meaning?

6702959fe52e7c8f6978cdfee24a86fa

maby im stupid but where do i find deviceid? what deviceid?

Load more comments