Dashticz - Custom JS
Moderators: leecollings, htilburgs, robgeerts
-
- Posts: 744
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Dashticz - Custom JS
Section for Custom.jss questions
-
- Posts: 744
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Dashticz - Custom JS
In my custom.js I have defined for a long time that a energy consumption block 142_1 will receive a green background when my solar panels cause a 'negative' value. This works fine.
My problem now is with my 2nd trial: based on switch/block 80, I want block 181 to change color when this switch/block 80 = 'On'. Unfortunately this doesn't work, unless when I change the if statement to the one of the energy block (which of course doesn't make sense), than the block changes color correctly. What is wrong in my custom.js?
custom.js:
custom.css:
I found the solution:
In my innocence
I didn't realize what parsefloat meant in the custom.js file. Only today I googled it and... understood:
Instead of:
if(parseFloat(device['Status'])=='On'){
I now have changed it into:
if(device['Status']=='On'){
Now I also understand why Dasticz was able to calculate with the
if(parseFloat(device['UsageDeliv'])>0){
because when I run the json command to retrieve all paramaters, the 'UsageDeliv' is shown as xyz Watt and not just xyz. The 'parsefloat' function strips the first number out of a string for use in calculations.
My problem now is with my 2nd trial: based on switch/block 80, I want block 181 to change color when this switch/block 80 = 'On'. Unfortunately this doesn't work, unless when I change the if statement to the one of the energy block (which of course doesn't make sense), than the block changes color correctly. What is wrong in my custom.js?
custom.js:
- Spoiler: show
custom.css:
- Spoiler: show
I found the solution:
In my innocence

Instead of:
if(parseFloat(device['Status'])=='On'){
I now have changed it into:
if(device['Status']=='On'){
Now I also understand why Dasticz was able to calculate with the
if(parseFloat(device['UsageDeliv'])>0){
because when I run the json command to retrieve all paramaters, the 'UsageDeliv' is shown as xyz Watt and not just xyz. The 'parsefloat' function strips the first number out of a string for use in calculations.
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
I like to change the textcolor of the lastupdate to red, when lastupdate is computed more than 2 hours ago.
@robgeerts provided me with the custom.js code:
I personally think the problem is in the $('div.block_153').addClass('lu_warningred'); part, but I can't seem to find the solution.
Anybody?
@robgeerts provided me with the custom.js code:
- Spoiler: show
- Spoiler: show
I personally think the problem is in the $('div.block_153').addClass('lu_warningred'); part, but I can't seem to find the solution.
Anybody?
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
-
- Posts: 1273
- Joined: Saturday 24 January 2015 22:12
- Target OS: NAS (Synology & others)
- Domoticz version: 3.7067
- Location: NL
- Contact:
Re: Dashticz - Custom JS
Could you try the following:
custom.js:
Maybae you also have to do this in custom.css
custom.js:
Code: Select all
function getStatus_153(idx,value,device){
if(moment(device['LastUpdate']).unix()<(moment().unix()-(3600*8))){
$('div.block_153 .lastupdate').addClass('lu_warningred');
}
else {
$('div.block_153 .lastupdate').removeClass('lu_warningred');
}
}
Code: Select all
.lastupdate.lu_warningred {
color: red !important;
}
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Dashticz - Custom JS
I have this one. This block stays red, whether 'ketel' is on or off. I want it to be red only if it's on. Tried it with the solution for the 'aanwezig' button , but somehow that isn't working
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
No, doesn't workrobgeerts wrote: ↑Wednesday 15 November 2017 20:55 Could you try the following:
custom.js:Maybae you also have to do this in custom.cssCode: Select all
function getStatus_153(idx,value,device){ if(moment(device['LastUpdate']).unix()<(moment().unix()-(3600*8))){ $('div.block_153 .lastupdate').addClass('lu_warningred'); } else { $('div.block_153 .lastupdate').removeClass('lu_warningred'); } }
Code: Select all
.lastupdate.lu_warningred { color: red !important; }

Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
-
- Posts: 1273
- Joined: Saturday 24 January 2015 22:12
- Target OS: NAS (Synology & others)
- Domoticz version: 3.7067
- Location: NL
- Contact:
Re: Dashticz - Custom JS
I tested this in custom.js, and that does work...
I had to add a timeout, otherwise it couldnt do that because that block didnt have content yet..
I had to add a timeout, otherwise it couldnt do that because that block didnt have content yet..
Code: Select all
function getStatus_153(idx,value,device){
setTimeout(function(){
if(moment(device['LastUpdate']).unix()<(moment().unix()-(3600*2))){
$('div.block_153 span.lastupdate').addClass('lu_warningred');
}
else {
$('div.block_153 span.lastupdate').removeClass('lu_warningred');
}
},1000);
}
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
Hi Rob,
If I use the last code with the timeout function, than it works for me to:
But when I do the same without the forced timeout, nothing happens while there is a timeout?!
Strange, isn't it??
If I use the last code with the timeout function, than it works for me to:
Code: Select all
function getStatus_153(idx,value,device){
setTimeout(function(){
if(moment(device['LastUpdate']).unix()<(moment().unix()-(3600*2))){
$('div.block_153 span.lastupdate').addClass('lu_warningred');
}
else {
$('div.block_153 span.lastupdate').removeClass('lu_warningred');
}
},1000);
}
Code: Select all
.lastupdate.lu_warningred{
color: red !important;
}
Code: Select all
</s>function getStatus_153(idx,value,device){
if(moment(device['LastUpdate']).unix()<(moment().unix()-(3600*1))){
$('div.block_153 span.lastupdate').removeClass('lu_warningyellow').addClass('lu_warningred');
}
else {
$('div.block_153 span.lastupdate').removeClass('lu_warningred').addClass('lu_warningyellow');
}
}
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
-
- Posts: 1273
- Joined: Saturday 24 January 2015 22:12
- Target OS: NAS (Synology & others)
- Domoticz version: 3.7067
- Location: NL
- Contact:
Re: Dashticz - Custom JS
"But when I do the same without the forced timeout, nothing happens while there is a timeout?!"
Uhhhh... say what?
Uhhhh... say what?
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
Yip, that’s what I say.
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
-
- Posts: 1273
- Joined: Saturday 24 January 2015 22:12
- Target OS: NAS (Synology & others)
- Domoticz version: 3.7067
- Location: NL
- Contact:
Re: Dashticz - Custom JS
Je zegt dat als je het zonder timeout doet er niks gebeurd terwijl je wel een timeout hebt...
You say it does nothing without a timeout but you do have a timeout

You say it does nothing without a timeout but you do have a timeout

- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
Klopt, zonder het timeout script in het script, terwijl er wel een timeout is gebeurt er niets....
Right, without the timeout command in the script, while I have a timeout, nothing happens....
current entry in config.js
current entry in custom.css
current json output

Right, without the timeout command in the script, while I have a timeout, nothing happens....

current entry in config.js
Code: Select all
function getStatus_153(idx,value,device){
if(moment(device['LastUpdate']).unix()<(moment().unix()-(3600*1))){
$('div.block_153 span.lastupdate').addClass('lu_warningred');
}
else {
$('div.block_153 span.lastupdate').removeClass('lu_warningred');
}
}
Code: Select all
.lu_warningred{
color: red !important;
}
Code: Select all
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 18,
"Data" : "On",
"Description" : "",
"Favorite" : 1,
"HardwareID" : 7,
"HardwareName" : "Dummy Virtual Switch",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveDimmer" : true,
"HaveGroupCmd" : true,
"HaveTimeout" : false,
"ID" : "000140E9",
"Image" : "Phone",
"IsSubDevice" : false,
"LastUpdate" : "2017-11-16 15:50:02",
"Level" : 0,
"LevelInt" : 0,
"MaxDimLevel" : 100,
"Name" : "iPhone Nassira",
"Notifications" : "false",
"PlanID" : "2",
"PlanIDs" : [ 2 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "On",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "Switch",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "Light/Switch",
"TypeImg" : "lightbulb",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "627",
"YOffset" : "370",
"idx" : "153"
}
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
- DewGew
- Posts: 581
- Joined: Thursday 21 April 2016 12:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10618
- Location: Sweden
- Contact:
Re: Dashticz - Custom JS
I have add icon fa-spinner for one of my devices (pump). When i put it in like this:
- Icon is not rotating
- Icon is rotating
Is it possible to add the class "fa-spin" only when device is on with custom.css and custom.js?
Code: Select all
blocks[123]['icon'] = 'fa-spinner';
Code: Select all
blocks[123]['icon'] = 'fa-spinner fa-spin';
Is it possible to add the class "fa-spin" only when device is on with custom.css and custom.js?
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
-
- Posts: 1273
- Joined: Saturday 24 January 2015 22:12
- Target OS: NAS (Synology & others)
- Domoticz version: 3.7067
- Location: NL
- Contact:
Re: Dashticz - Custom JS
@DewGew, kun je dit eens proberen:
@htilburgs, but where is the timeout coming from then?
Why dont you add it to the 'getStatus_153'-function?
Code: Select all
function getStatus_123(idx,value,device){
setTimeout(function(){
if(device['Data']=='On'){
$('div.block_123 .col-icon .fa').addClass('fa-spin');
}
else {
$('div.block_123 .col-icon .fa').removeClass('fa-spin');
}
},1000);
}
Why dont you add it to the 'getStatus_153'-function?
- DewGew
- Posts: 581
- Joined: Thursday 21 April 2016 12:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10618
- Location: Sweden
- Contact:
Re: Dashticz - Custom JS
@robgeerts, Thanks I try that
but it seems that custom.js is not loading in lataste beta??

Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
-
- Posts: 1273
- Joined: Saturday 24 January 2015 22:12
- Target OS: NAS (Synology & others)
- Domoticz version: 3.7067
- Location: NL
- Contact:
Re: Dashticz - Custom JS
I saw you did a PR with a fix for the loading? did you try my code after it?
- DewGew
- Posts: 581
- Joined: Thursday 21 April 2016 12:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.10618
- Location: Sweden
- Contact:
Re: Dashticz - Custom JS
I havent tested latest beta only own setup. Seems to work here.robgeerts wrote:I saw you did a PR with a fix for the loading? did you try my code after it?
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
For my iPhone devices I like to change the text "AAN" and "UIT" to "AANWEZIG" and "AFWEZIG". For this I have a custom.JS part
I've havent't used this for a while and this used to work, but for some reason it doesn't work anymore.
I can't find out where the issue is.
I've havent't used this for a while and this used to work, but for some reason it doesn't work anymore.
I can't find out where the issue is.
Code: Select all
// Function for modified status - iPhone Harm
function getBlock_150(device,idx){ //idx 150 - iPhone Harm
$('.block_'+idx).attr('switchDevice(this)');
var html='';
html+='<div class="col-xs-4 col-icon">';
if(device['Status']=='Off') html+=iconORimage(idx,'fa-toggle-off','','off icon');
else html+=iconORimage(idx,'fa-toggle-on','','on icon');
html+='</div>';
html+='<div class="col-xs-8 col-data">';
html+='<strong class="title">'+device['Name']+'</strong><br />';
if(device['Status']=='Off') html+='<span class="state">AFWEZIG</span>';
else html+='<span class="state">AANWEZIG</span>';
// check if device has show_last_update=true
if((_SHOW_LASTUPDATE && (typeof(blocks[idx])=='undefined' || typeof(blocks[idx]['hide_lastupdate'])=='undefined' || blocks[idx]['hide_lastupdate']===false)) || (!_SHOW_LASTUPDATE && (typeof(blocks[idx])!=='undefined' && typeof(blocks[idx]['show_lastupdate'])!=='undefined' && blocks[idx]['show_lastupdate']==true)) )
{
html+='<br /><span class="lastupdate">'+moment(device['LastUpdate']).format(_LASTUPDATE_FORMAT)+'</span>';
}
html+='</div>';
return html;
}
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Dashticz - Custom JS
I've send you mine, but... not sure if it works anymore. Didn't check it in ages.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Dashticz - Custom JS
With the help of Edwin, I've narrowed down my problem. When I leave the lastupdate part out of the code, it works.
So, now the question is: how to get this working again with the lastupdate part... 
Code: Select all
// check if device has show_last_update=true
if((_SHOW_LASTUPDATE && (typeof(blocks[idx])=='undefined' || typeof(blocks[idx]['hide_lastupdate'])=='undefined' || blocks[idx]['hide_lastupdate']===false)) || (!_SHOW_LASTUPDATE && (typeof(blocks[idx])!=='undefined' && typeof(blocks[idx]['show_lastupdate'])!=='undefined' && blocks[idx]['show_lastupdate']==true)) )
{
html+='<br /><span class="lastupdate">'+moment(device['LastUpdate']).format(_LASTUPDATE_FORMAT)+'</span>';
}
html+='</div>';

Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
Who is online
Users browsing this forum: Google [Bot] and 1 guest