Page 1 of 1

help with function getStatus_2103_1

Posted: Sunday 17 January 2021 15:48
by pvklink
Hi i have a device that show the usage of my wasmachine.
I use id '2103_1' in config.js to show this device

I have the following function to change the ico and the title text, but it does work (anymore)
Can somebody give some help, how to get this working again?
When the wasmachine is in rest, it uses "0.7 Watt" (part two of the IF)
When it is more then 2, it is on... (part 1 of the IF)

2103 is the domoticzID 2103_1 in dashticz

function getStatus_2103_1(block) {
var usage = block.device.value;
if (parseFloat(usage) > 2) {
block.icon = 'fas fa-thermometer-full'
block.title = 'Wasmachine Aan'
} else {
block.icon = 'fas fa-thermometer-half'
block.title = 'Wasmachine Uit'
}
}

setting config.js
blocks['2103_1']= {title: 'Was machine', icon: 'fas fa-thermometer-half', hide_data: true, width: 4, switch: true, last_update: false}


dashtix userinterface (part)
wasm.jpg
wasm.jpg (9.26 KiB) Viewed 156 times

Code: Select all

{
	"ActTime" : 1610906808,
	"AstrTwilightEnd" : "19:05",
	"AstrTwilightStart" : "06:41",
	"CivTwilightEnd" : "17:43",
	"CivTwilightStart" : "08:03",
	"DayLength" : "08:23",
	"NautTwilightEnd" : "18:25",
	"NautTwilightStart" : "07:21",
	"ServerTime" : "2021-01-17 19:06:48",
	"SunAtSouth" : "12:53",
	"Sunrise" : "08:42",
	"Sunset" : "17:04",
	"app_version" : "2020.2 (build 12847)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CounterToday" : "2.150 kWh",
			"CustomImage" : 0,
			"Data" : "179.430 kWh",
			"Description" : "",
			"EnergyMeterMode" : "0",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 31,
			"HardwareName" : "zwavepluspvk",
			"HardwareType" : "OpenZWave USB",
			"HardwareTypeVal" : 21,
			"HaveTimeout" : false,
			"ID" : "00000E01",
			"LastUpdate" : "2021-01-17 19:06:30",
			"Name" : "wasmachine_kwh_oud3",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "kWh",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "current",
			"Unit" : 1,
			"Usage" : "0.7 Watt",
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "2103"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Re: help with function getStatus_2103_1

Posted: Sunday 17 January 2021 21:03
by Lokonli
pvklink wrote: Sunday 17 January 2021 15:48 Hi i have a device that show the usage of my wasmachine.
I use id '2103_1' in config.js to show this device

I have the following function to change the ico and the title text, but it does work (anymore)
Can somebody give some help, how to get this working again?
When the wasmachine is in rest, it uses "0.7 Watt" (part two of the IF)
When it is more then 2, it is on... (part 1 of the IF)

2103 is the domoticzID 2103_1 in dashticz

function getStatus_2103_1(block) {
var usage = block.device.value;
if (parseFloat(usage) > 2) {
block.icon = 'fas fa-thermometer-full'
block.title = 'Wasmachine Aan'
} else {
block.icon = 'fas fa-thermometer-half'
block.title = 'Wasmachine Uit'
}
}

setting config.js
blocks['2103_1']= {title: 'Was machine', icon: 'fas fa-thermometer-half', hide_data: true, width: 4, switch: true, last_update: false}


dashtix userinterface (part)
wasm.jpg

Code: Select all

{
	"ActTime" : 1610906808,
	"AstrTwilightEnd" : "19:05",
	"AstrTwilightStart" : "06:41",
	"CivTwilightEnd" : "17:43",
	"CivTwilightStart" : "08:03",
	"DayLength" : "08:23",
	"NautTwilightEnd" : "18:25",
	"NautTwilightStart" : "07:21",
	"ServerTime" : "2021-01-17 19:06:48",
	"SunAtSouth" : "12:53",
	"Sunrise" : "08:42",
	"Sunset" : "17:04",
	"app_version" : "2020.2 (build 12847)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CounterToday" : "2.150 kWh",
			"CustomImage" : 0,
			"Data" : "179.430 kWh",
			"Description" : "",
			"EnergyMeterMode" : "0",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 31,
			"HardwareName" : "zwavepluspvk",
			"HardwareType" : "OpenZWave USB",
			"HardwareTypeVal" : 21,
			"HaveTimeout" : false,
			"ID" : "00000E01",
			"LastUpdate" : "2021-01-17 19:06:30",
			"Name" : "wasmachine_kwh_oud3",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "kWh",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "current",
			"Unit" : 1,
			"Usage" : "0.7 Watt",
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "2103"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}
The first line in the function is incorrect:

Code: Select all

var usage = block.device.value;
As you can see in the Domoticz device json dump, you see there is no key 'value' in the result part.
Probaby you want to use the field 'Usage'

so change the line to the following:

Code: Select all

var usage = block.device.Usage;
Javascript is case sensitive.
All Domoticz device fields, except idx, start with an uppercase character. So 'block.device.usage' will not work.