If you follow the above, you'll see something like this in the DevTools console tab:
Code: Select all
{
"AddjMulti": 1,
"AddjMulti2": 1,
"AddjValue": 0,
"AddjValue2": 0,
"BatteryLevel": 255,
"Counter": "16344.860",
"CounterDeliv": "14825.054",
"CounterDelivToday": "7.994 kWh",
"CounterToday": "3.332 kWh",
"CustomImage": 0,
"Data": "10511199;5833661;4382068;10442986;0;2530",
"Description": "",
"Favorite": 1,
"HardwareDisabled": false,
"HardwareID": 7,
"HardwareName": "P1 Smart Meter",
"HardwareType": "P1 Smart Meter with LAN interface",
"HardwareTypeVal": 5,
"HaveTimeout": false,
"ID": "0001",
"LastUpdate": "2022-03-03 12:35:41",
"Name": "Power",
"Notifications": "false",
"PlanID": "4",
"PlanIDs": [
4,
3
],
"Protected": false,
"ShowNotifications": true,
"SignalLevel": "-",
"SubType": "Energy",
"SwitchTypeVal": 0,
"Timers": "false",
"Type": "P1 Smart Meter",
"TypeImg": "counter",
"Unit": 1,
"Usage": "0 Watt",
"UsageDeliv": "2530 Watt",
"Used": 1,
"XOffset": "447",
"YOffset": "81",
"idx": "43",
"Data0": "10511199",
"Data1": "5833661",
"Data2": "4382068",
"Data3": "10442986",
"Data4": "0",
"Data5": "2530",
"NettUsage": -2530,
"NettCounterToday": -4.662,
"NettCounter": 1519.8060000000005
}
And here you see the problem: Usage and UsageDeliv are both strings with the text 'Watt' at the end: Your subtraction will not work.
Good news: The computed field NettUsage has already been added automatically. You can use this field.
Further, for every subdevice it's 'own' getStatus function will be called as well. You can use this to simplify the code:
Code: Select all
function getStatus_142_1(block) { //I've added _1 ! (this this the subdevice)
if(block.device.NettUsage < 0 )
block.addClass='background_green' //directly manipulate the block itself.
else
block.addClass=''
}
or as oneliner:
Code: Select all
function getStatus_142_1(block) { //I've added _1 ! (this this the subdevice)
block.addClass= block.device.NettUsage < 0 ? 'background_green':''; //ternary operator
}