custom js Topic is solved

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

custom js

Post 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
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: custom js

Post 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'; 
}
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: custom js

Post 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.
Blah blah blah
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: custom js

Post 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.
Lokonli
Posts: 2291
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: custom js

Post 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?
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: custom js

Post 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 :)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: custom js

Post by Vomera »

Would be very nice!!
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: custom js

Post by HansieNL »

Can the icon for Longfonds made customizable (icon/image)? Or can we easily change that by css?
Blah blah blah
Lokonli
Posts: 2291
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: custom js

Post 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.
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: custom js

Post 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
Blah blah blah
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: custom js

Post 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
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: custom js

Post by EdwinK »

How about a skull if the airquality is in the red's :)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: custom js

Post 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
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: custom js

Post 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 ?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest