dashticz dynamic price - background color red to green

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
renerene
Posts: 340
Joined: Wednesday 03 August 2016 11:36
Target OS: -
Domoticz version:
Contact:

dashticz dynamic price - background color red to green

Post by renerene »

Would be great to have the background of my kitchen dashticz wall tablet showing the current kwh price (cheap = green, red = expensive)

There is already a device (dummy sensor) available that holds the position of the price index, being 1 for the cheapest hour and 24 for the most expensive hour.

Is there a guru here can give directions how to accomplish this?

In the kitchen of Eric Oud Ammerveld (45) stands
a remarkable piece of equipment. Not to cook with, but
cooking, but to decide when he will
do. It is an upright light meter, a sort of
kind of traffic light, which the IT guy from
Bleiswijk made himself.
“The meter shows when I can buy electricity cheaply
can buy electricity cheaply,” he explains. “When it's red the power is
expensive, at green I don't have to pay anything for it.”
The latter is possible at times when it is hard
wind and the surplus of wind energy for
extremely low or even negative electricity prices
causes.

https://www.trouw.nl/duurzaamheid-econo ... google.nl/
JBN
Posts: 40
Joined: Saturday 13 July 2013 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sweden
Contact:

Re: dashticz dynamic price - background color red to green

Post by JBN »

Well, I assume you can do this in several ways. This is one I just tried with.

You need to add (or change) your custom.js file and add something that changes the background. I suggest adding the code in beforeFirstRenderHook().

In this code I have a switch device (<YOUR DEVICE ID>) that can be on or off, if you have something other you can add more complicated logic.
I simply change the defined screen[1]["background"] image to another. If you want red as an example you need to add that as a background image.

Code: Select all

function beforeFirstRenderHook() {
    var device = Domoticz.getAllDevices(<YOUR_DEVICE_ID>);
    if(device.Data === "Off") {
        screens[1]["background"] = 'bg0.jpg';
    }

    if(device.Data === "On") {
        screens[1]["background"] = 'bg9.jpg';
    }
}
You also need to make sure the Dashticz interface is refreshed periodically. This can be done with altering:

Code: Select all

config['dashticz_refresh'] = '1'; 
Where 1 is one minute, I think default is every 60 minutes.
Lokonli
Posts: 2268
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dashticz dynamic price - background color red to green

Post by Lokonli »

You could use the deviceHook function. Then you don’t have to refresh Dashticz.

See https://dashticz.readthedocs.io/en/beta ... evice-hook
JBN
Posts: 40
Joined: Saturday 13 July 2013 8:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sweden
Contact:

Re: dashticz dynamic price - background color red to green

Post by JBN »

Ah! And I realized I should change the CSS instead. Class "screen" might be ok in the scenario the OP has.

Code: Select all

function deviceHook(device) {
    if (device.idx==<DEVICEID>) {
        var col = (device.Data === 'Off') ? 'green' :'blue';
        var elements = document.getElementsByClassName("screen");
        for(var i=0 ; i< elements.length; i++){
            elements[i].style.background = col;
        }
    }
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest