.js Function user variables

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
Enz0jacco
Posts: 45
Joined: Tuesday 03 March 2020 8:15
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

.js Function user variables

Post by Enz0jacco »

hey guys,

i've got the following situation:

I use two user variables which can only be either 'Open' or 'Closed'

I want the background color to change according this status.
I tried the following but my js knowledge is not very good:

Code: Select all

function getStatus_v18(block){
var idx = block.idx;
var device = block.device;
   if(parseString(device['Data'])='Open'){
      block.addClass='Klepopen';
   }
   else {
      block.addClass='Klepdicht';
   }
}
any ideas?
User avatar
madpatrick
Posts: 659
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: .js Function user variables

Post by madpatrick »

This is my setup.

in custom.js

Code: Select all


var trigger_207 = false; //Alarm modefunction getStatus_207(block) 
function getStatus_207(block) {
    var Data = block.device.Data;
    var idx = block.idx;
    var device = block.device;

    if(device['Status']=='On') {
        trigger_207 = true;
        block.addClass = 'warning1';	// set the addClass parameter for block 207
    }
    else {
        trigger_207 = false;
        block.addClass = ''; 		// reset the addClass parameter for block 
    }
    handleWarning();
}


in custom.css

Code: Select all

.warning1 {
   	background: rgba(255,0,0,0.6) !important;
	background-clip: padding-box;
	border: 3px solid white !important;
	border-radius: 15px!important;
}
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.14b on Tab8" =-
Lokonli
Posts: 2287
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .js Function user variables

Post by Lokonli »

Enz0jacco wrote: Saturday 19 December 2020 9:59 hey guys,

i've got the following situation:

I use two user variables which can only be either 'Open' or 'Closed'

I want the background color to change according this status.
I tried the following but my js knowledge is not very good:

Code: Select all

function getStatus_v18(block){
var idx = block.idx;
var device = block.device;
   if(parseString(device['Data'])='Open'){
      block.addClass='Klepopen';
   }
   else {
      block.addClass='Klepdicht';
   }
}
any ideas?
The if statement is wrong. Change it to:

Code: Select all

if(parseString(device['Data'])=='Open'){
(The single '=' is an assignment, for comparison use '==')
Enz0jacco
Posts: 45
Joined: Tuesday 03 March 2020 8:15
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: .js Function user variables

Post by Enz0jacco »

omg silly me, I could've known that.

unfortunately that was not the only problem.
I think maybe that var device and data is not correct but I'm not sure what it should be as it is a user variable.
Lokonli
Posts: 2287
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .js Function user variables

Post by Lokonli »

O yes, indeed.

For variables it's device['Value'] instead of device['Data']
Enz0jacco
Posts: 45
Joined: Tuesday 03 March 2020 8:15
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: .js Function user variables

Post by Enz0jacco »

Ok did that and now I think there is something wrong with the getstatus part. I tried to put the v18 between quotes but that doesnt do the trick either.
Lokonli
Posts: 2287
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .js Function user variables

Post by Lokonli »

And remove parseString...

Sent from my SM-A320FL using Tapatalk

Enz0jacco
Posts: 45
Joined: Tuesday 03 March 2020 8:15
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: .js Function user variables

Post by Enz0jacco »

ah makes sense ! its working perfectly thnx again!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest