Page 1 of 1

custom js

Posted: Saturday 13 July 2019 17:47
by pvklink
Hi, i have a switch (usage kwh) id 982_1 that i show in Dashticz. Normally it the icon is white and it uses always 0.6 kw.
When the wasmachine is executing it uses more than 0,8 i like it to be red.

I added the following code to custom.js.
When the machine is activate (and a washing program it uses more power then 0,8 ... but the switch does not get red...

Code: Select all

  //add custom javascript in here
function afterGetDevices(){
	
	
}

// 1 powerusage then red
function getChange_982_1(idx,value,device){
if(parseFloat(device['Power Usage'])>1){
blocks['982_1']['icon'] = 'fas fa-thermometer-full'; 
}

else {
blocks['982_1']['icon'] = 'fas fa-thermometer-half'; 
}
}

these are exported csv data from the wasmachine

DateTime,"Energieverbruik","Power Usage"
2019-07-12 19:00:00,0,0,7
2019-07-12 19:05:00,,0,7
2019-07-12 19:10:00,,0,7
2019-07-12 19:15:00,,0,7
2019-07-12 19:20:00,,0,6

xls
DateTime Energieverbruik Power Usage Energieverbruik Power Usage
12-7-2019 19:00 0,00
12-7-2019 19:05 0,70
12-7-2019 19:10 0,70
12-7-2019 19:15 0,70
12-7-2019 19:20 0,60
12-7-2019 19:25 0,70
12-7-2019 19:30 0,70
12-7-2019 19:35 0,70

Re: custom js

Posted: Saturday 13 July 2019 23:02
by pvklink
Think i solved it..
i did a http://192.168.20.35:82/json.htm?type=devices&rid=982
and saw that the property of this kwh device = Usage, so i used that!

Code: Select all

// add custom javascript in here
//
// check properties en kijk welke wijzigt evt lastupdate nemen
//  "Usage" : "3 Watt", neemt js wel t getal en heeft het geen last van Watt als text?
//
function afterGetDevices(){
	
	
}

function getExtendedBlockTypes(blocktypes){
	//blocktypes.Type['Lighting 2'] = { icon: 'fa fa-lightbulb-o', title: '<Name>', value: 'ds' }
	return blocktypes;
} 
//0,8
function getChange_982_1(idx,value,device){
//if(parseFloat(device['Power'])>1){
if(parseFloat(device['Usage'])>1){
blocks['982_1']['icon'] = 'fas fa-thermometer-full'; 
}

else {
blocks['982_1']['icon'] = 'fas fa-thermometer-half'; 
}
}

Re: custom js

Posted: Friday 26 July 2019 23:40
by HansieNL
I have multiple devices where I want add/remove the same class.
Is it possible to simplify/reduce this code?

Code: Select all

function afterGetDevices(){
  //Notebook PC
  if (alldevices[350].Data == 'Off') {
    $('.block_350 .col-data').addClass('data-off');
  }
  else {
    $('.block_350 .col-data').removeClass('data-off');
  }
  //Desktop PC
  if (alldevices[351].Data == 'Off') {
    $('.block_351 .col-data').addClass('data-off');
  }
  else {
    $('.block_351 .col-data').removeClass('data-off');
  }
...and some more devices...  
}
Any help welcome. Thanks.

Re: custom js

Posted: Tuesday 30 July 2019 15:41
by Vomera
Tnx for this post, i was also stuck on the power, now i understand the "device['Usage']" part haha.
Is this also possible with the data from "longfonds" I want to color this too, but the data is not pushed from domoticz.

Re: custom js

Posted: Tuesday 30 July 2019 16:06
by Lokonli
Vomera wrote: Tuesday 30 July 2019 15:41 Tnx for this post, i was also stuck on the power, now i understand the "device['Usage']" part haha.
Is this also possible with the data from "longfonds" I want to color this too, but the data is not pushed from domoticz.
No, that's not possible.

What I could make is the addition of a custom class depending on a value of the block. For instance:

Blocks['longfonds'] = {
classRules: {
'green': '<2',
'orange: '<6',
'red': '>6'
}

Then you can use this class in custom.css to set the visual properties.

First valid class rule will be applied.

This should work for all blocks ...

Interested?

Re: custom js

Posted: Tuesday 30 July 2019 19:50
by EdwinK
Lokonli wrote: Tuesday 30 July 2019 16:06
What I could make is the addition of a custom class depending on a value of the block. For instance:

Blocks['longfonds'] = {
classRules: {
'green': '<2',
'orange: '<6',
'red': '>6'
}

Then you can use this class in custom.css to set the visual properties.

First valid class rule will be applied.

This should work for all blocks ...

Interested?
Sounds good enough for me :)

Re: custom js

Posted: Tuesday 30 July 2019 21:22
by Vomera
Would be very nice!!

Re: custom js

Posted: Tuesday 30 July 2019 22:01
by HansieNL
Can the icon for Longfonds made customizable (icon/image)? Or can we easily change that by css?

Re: custom js

Posted: Tuesday 30 July 2019 23:16
by Lokonli
HansieNL wrote: Tuesday 30 July 2019 22:01 Can the icon for Longfonds made customizable (icon/image)? Or can we easily change that by css?
I will add this to the feature request list.

Re: custom js

Posted: Tuesday 30 July 2019 23:41
by HansieNL
Lokonli wrote: Tuesday 30 July 2019 23:16
HansieNL wrote: Tuesday 30 July 2019 22:01 Can the icon for Longfonds made customizable (icon/image)? Or can we easily change that by css?
I will add this to the feature request list.
Thanks,
I think I've got some kind of icon fetishism
Image

Re: custom js

Posted: Wednesday 31 July 2019 10:12
by Vomera
HansieNL wrote: Tuesday 30 July 2019 23:41
Lokonli wrote: Tuesday 30 July 2019 23:16
HansieNL wrote: Tuesday 30 July 2019 22:01 Can the icon for Longfonds made customizable (icon/image)? Or can we easily change that by css?
I will add this to the feature request list.
Thanks,
I think I've got some kind of icon fetishism
Image
Haha that would be a nice icon !! :D

Re: custom js

Posted: Wednesday 31 July 2019 11:57
by EdwinK
How about a skull if the airquality is in the red's :)

Re: custom js

Posted: Thursday 01 August 2019 10:13
by Vomera
EdwinK wrote: Wednesday 31 July 2019 11:57 How about a skull if the airquality is in the red's :)

we requested this a few post back, i'll hope they make it :D

Re: custom js

Posted: Thursday 13 February 2020 16:54
by Vomera
Vomera wrote: Thursday 01 August 2019 10:13
EdwinK wrote: Wednesday 31 July 2019 11:57 How about a skull if the airquality is in the red's :)

we requested this a few post back, i'll hope they make it :D
Any news about this ? didn't see it in the release notes ? :) or is it still on the list ?