Page 1 of 1

dashticz dynamic price - background color red to green

Posted: Wednesday 08 January 2025 19:48
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/

Re: dashticz dynamic price - background color red to green

Posted: Thursday 09 January 2025 22:09
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.

Re: dashticz dynamic price - background color red to green

Posted: Friday 10 January 2025 18:15
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

Re: dashticz dynamic price - background color red to green

Posted: Friday 10 January 2025 21:51
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;
        }
    }
}