Struggle with custom getStatus function – never called

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
mlinzner2
Posts: 4
Joined: Thursday 05 January 2023 8:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Struggle with custom getStatus function – never called

Post by mlinzner2 »

I'm working on an energy dashboard and would like to adjust price per m3 / price per kWh based on dates. If I understand correctly, this is what getStatus in the custom\.js is made for.

Bare minimum config file I have right now:

Code: Select all

var config = {};
config["domoticz_ip"] = "[xxxxxx]";

blocks["costs"] = {
  title: "costs",
  devices: [97, 101],
  graph: ["line", "bar", "bar", "bar"],
  stacked: true,
  tooltiptotal: false,
  custom: {
    "last week": {
      range: "month",
      filter: "1 weeks",
      data: {
        total:
          "(d\.v_101*3\.33211)+(d\.v2_97*0\.75636)-(d\.r2_97*0\.109)+(d\.v_97*0\.82933)-(d\.r1_97*0\.109)",

        electricity_night: "(d\.v_97*0\.82933)-(d\.r1_97*0\.109)",
        electricity_day: "(d\.v2_97*0\.75636)-(d\.r2_97*0\.109)",
        gas: "d\.v_101*3\.33211",      
        },
    },
  },
};

columns[2] = {};
columns[2]["blocks"] = ["costs"];

var screens = {};
screens[1] = {};
screens[1]["background"] = "xxx";
screens[1]["columns"] = [2];
The hardcoded Kilowatt/Cubicmeter prices (3\.33211, …) I would like to adjust based on the date information available in d\.d_101 or d\.d_97.

Given the above configuration, I assumed that I can add getStatus_costs to my custom\.js and it should be called. So my file looks like this:

Code: Select all

function getStatus_costs(block) {
  console\.log("GET_STATUS_COSTS");
}
But the function is not called at all.

If I add afterGetDevices(), getExtendedBlockTypes() or deviceHook() to the same file, they get called, but I think they are not useful to what I want to achieve.


I'm currently running Domoticz Version 2022\.2 and Dashticz Version: 3\.10\.01.

What else could I do to debug this issue? Or is there any other way to achieve my required outcome? Any help is appreciated!

Please ignore the escaped dots, how on earth can I get around the external URL detection? :D
Lokonli
Posts: 2290
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Struggle with custom getStatus function – never called

Post by Lokonli »

The getStatus function only gets called for Domoticz device blocks (switches, sensors etc.), not for graphs.

However, the data for a custom graph are calculated by the javascript function 'eval' meaning you can call any function.

For instance:

Code: Select all

total:
          "(d.v_101*getValue1())+(d.v2_97*getValue2())-(d.r2_97*getValue3())+(d.v_97*getValue4())-(d.r1_97*getValue5())",
and then just define the getValuex() functions in custom.js.

Alternative:
create a custom sensor in Domoticz, one for each value.
Then you can include the graph data of these sensors in your graph as well.
mlinzner2
Posts: 4
Joined: Thursday 05 January 2023 8:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Struggle with custom getStatus function – never called

Post by mlinzner2 »

Lokonli wrote: Thursday 05 January 2023 16:28 However, the data for a custom graph are calculated by the javascript function 'eval' meaning you can call any function.

For instance:

Code: Select all

total:
          "(d\.v_101*getValue1())+(d\.v2_97*getValue2())-(d\.r2_97*getValue3())+(d\.v_97*getValue4())-(d\.r1_97*getValue5())",
and then just define the getValuex() functions in custom\.js.
Amazing that would solve it! One last thing: What is the best way to access the dates inside the custom functions? The dates are available in d\.d_101 and d\.d_97 as Strings (eg "2023-01-05"). I tried to pass the date string into the function like so

Code: Select all

getValue1(d\.d_101)
That results in undefined values.
I also tried to pass the entire data object d to the function, this adds a bunch of values but not the date (possibly all values that can be parsed as float?).

Code: Select all

{"c1_97":73\.09,"c2_97":2\.704,"c3_97":110\.813,"c4_97":3\.276,"r1_97":0,"r2_97":0\.054,"v_97":2\.164,"v2_97":11\.358,"v_101":4\.64}
Lokonli
Posts: 2290
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Struggle with custom getStatus function – never called

Post by Lokonli »

You would like to pass the date of the sample to the getValuex function?

ok, now we enter the trick area :)

You can add y.d as function parameter, like

Code: Select all

getValue1(y.d)
y.d is a javascript moment.js object. See https://momentjs.com/
mlinzner2
Posts: 4
Joined: Thursday 05 January 2023 8:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Struggle with custom getStatus function – never called

Post by mlinzner2 »

Lokonli wrote: Saturday 07 January 2023 13:48 ok, now we enter the trick area :)
😃 Amazing, works like a charm! The fact that it is a momentjs object also makes the date comparisons easier to deal with ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest