Tibber API - Controlling things depending on price for electricity for Tibber customers


My electricity supplier has an API and even wrote a smartapp/integration into Smartthings.
So I can see the current price per hour in my Smartthings app.
While it’s great to see it, I also want to be able to control things depending on price…
For example turn off the heater in the garage when it’s super expensive and turn it on when it’s not…
The code is here

Not understanding how this programming works it looks to me like it lists the capabilities “sensor” and " Energy Meter" but I can’t find it when trying to set up an automation of any kind…

metadata {
definition (name: “Tibber price device handler”, namespace: “Tibber”, author: “tibberdev”) {
capability “Sensor”
capability “Energy Meter”

Any suggestions on whats missing or what I’m not understanding… (Yeah I know, a lot but anyway :smiley: )

This is a device handler (see way down below for their SmartApp example), so make sure you know how to do that. You’ll need to manually create a device and then assign this DTH to it (the Type field). Here’s what that should look like:

Once you get all that done, you need to go into the device’s preferences/settings and enter an API Key you get from their site: (see more detail below)


Please NOTE:

All the tiles this creates (1 large and 8 small) will only be available in ST’s Classic mobile app, not the new app. The new app will only give you 1 tile for an energy meter, and that will probably be empty based upon my quick look through of the code.

You WILL still be able to reference the values this DTH uses in the new app (see below), but you won’t be able to see what those are without using the Classic app, or going into the IDE.

Those aren’t really as important as the attributes:

	attribute "price", "number"
	attribute "priceNextHour", "number"
	attribute "priceNextHourLabel", "string"
	attribute "pricePlus2Hour", "number"
	attribute "pricePlus2HourLabel", "string"
	attribute "priceMaxDay", "number"
	attribute "priceMaxDayLabel", "string"
	attribute "priceMinDay", "number"
	attribute "priceMinDayLabel", "string"
	attribute "currency", "string"

Those are what you want to look for in Automations and/or SmartApps. Once you create your device and use this DTH, it should update the values because it connects out to their API to get that info.

Here’s what that looks like in the new app:

Tibbler SmartApp example:

1 Like

‘Sensor’ is a capability that was/is used in the classic environment as a tag to indicate a device has attributes. Although long since marked as deprecated, it is still used by Groovy SmartApps (such as webCoRE and ActionTiles) to request access to multiple devices rather than having to select them by specific capabilities. It isn’t used in the new environment.

The ‘Energy Meter’ has a single ‘energy’ attribute that is being (ab)used to make the current price accessible in a standard attribute. If an app knows about the ‘Energy Meter’ capability it ought to be detectable, though using a non-standard unit might perhaps break things.

Otherwise all the price information is presented in custom attributes and working with those currently requires custom SmartApps or something like webCoRE.

1 Like

Thanks a lot for your very good explanation!!
Now it makes more sense!
Really appreciate it!

1 Like

Thanks for explaining it!
Appreciate it a lot!

1 Like

Sorry, just one last question…
Using the Tibber Thermostat example here I only get to choose Thermostats which I don’t have
But I do have a lot of sensors and wallplugs which can do the same things and would be able to use it
for other things as well like pool and stuff…
How do I change it from looking for only Thermostats to look for more things?
Or would that require rewriting the whole smart app?
Tested their price example app as well but it’s not close to done and I wouldn’t know how to continue that.

Sorry for all dumb questions.

LOL, there are no dumb questions here!

The smartapp you linked to is only written to support thermostats, and the way it’s written would be difficult to change. Your best bet would be to write something, or see if using an Automation in the new app would do the same thing.

Their example app is pretty basic and just turns off/on a switch based on a hardcoded value for price:

if(price > 50){ //do something when price is above some value

You basically need to find your new Tibbler device (under Which sensor to select) and then the switch to control (under the second Which switch to trigger).

It’s almost want you want, except you need to change the hard coded value for price (currently 50), or make that a selectable value within the app. Here are the changes that would need to be made to allow you to provide your own price value:

preferences {
  section ("Allow external service to control these things...") {
    input "priceSensor", "capability.sensor", required: true
    input "switch1", "capability.switch", required: true
    input "priceLimit", "number", title: "What's the price limit?", required: true


def handlePriceUpdate(price){
    if(price > priceLimit){ //do something when price is above some value

Via the mobile app, you can have as many instances of this SmartApp as you want. Basically one for each switch. If you want to be able to select multiple switched within the SmartApp, more changes will be needed.

Could those changes above help you out?

1 Like