[RESOLVED] How to control button states - Help needed

I need some help in making my iKettle application update the buttons on the dashboard.

I also need to change the icon based on state. Here is my json file…

Thanks if you can assist…

[code]{
“flashicon”: “FCDN.nl – Startpagina met de beste, leukste en handigste links”,
“imgIconTurnable”: “”,
“imgIconMin”: “FCDN.nl – Startpagina met de beste, leukste en handigste links”,
“imgIconMax”: “http://www.fibarouk.co.uk/wp-content/uploads/2014/08/iKettle_blue.png”,
“halloIconsDir”: “pics/hallo”,
“state_icons”: [
“iKettle_0.png”,
“iKettle_100.png”,

],
“x”: “2”,
“y”: “4”,
“iconText”: “0”,
“inScene”: “1”,
“DisplayStatus”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “BoilLevelStatus”,
“MinValue”: “0”,
“MaxValue”: “100”
},
“doc_url”: {
“doc_language”: 1,
“doc_manual”: 1,
“doc_version”: 1,
“doc_platform”: 0,
“doc_page”: “devices”
},
“ToggleButton”: 1,
“Tabs”: [
{
“Label”: {
“lang_tag”: “tabname_control”,
“text”: “Control”
},
“Position”: “0”,
“TabType”: “flash”,
“ControlGroup”: [
{
“id”: “1”,
“isSingle”: “1”,
“scenegroup”: “1”
},
{
“id”: “2”,
“isSingle”: “1”,
“scenegroup”: “1”
},
{
“id”: “3”,
“isSingle”: “1”,
“scenegroup”: “2”
},
{
“id”: “4”,
“isSingle”: “1”,
“scenegroup”: “3”
},
{
“id”: “5”,
“isSingle”: “1”,
“scenegroup”: “4”
},
{
“id”: “6”,
“isSingle”: “1”,
“scenegroup”: “5”
}
],
“SceneGroup”: [
{
“id”: “STATUS TEXT ON DASHBOARD”,
“id”: “1”,
“top”: “3.25”,
“left”: “-1.1”,
“x”: “2”,
“y”: “1”
},
{
“id”: “ON OFF ON DASHBOARD”,
“id”: “2”,
“top”: “0”,
“left”: “0”,
“x”: “2”,
“y”: “1”
},
{
“id”: “Keep Warm ON DASHBOARD”,
“id”: “3”,
“top”: “0”,
“left”: “0”,
“x”: “2”,
“y”: “1”
},
{
“id”: “4”,
“top”: “0”,
“left”: “0”,
“x”: “2”,
“y”: “1”
},
{
“id”: “5”,
“top”: “0”,
“left”: “0”,
“x”: “2”,
“y”: “1”
}
],
“Control”: [
{
“ControlGroup”: “1”,
“ControlType”: “variable”,
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “CmdStatus”,
“Top”: 260,
“Left”: 150,
“Width”: 175,
“Height”: 20
}
},
{
“ControlGroup”: “2”,
“ControlType”: “button”,
“top”: “-0.20”,
“left”: “2.1”,
“Label”: {
“lang_tag”: “boil”,
“text”: “Boil”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “BoilSwitchStatus”,
“Value”: “100”,
“Top”: 40,
“Left”: 150,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “Boil”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “100”
}
]
}
},
{
“ControlGroup”: “2”,
“ControlType”: “button”,
“top”: “-0.20”,
“left”: “1.1”,
“Label”: {
“lang_tag”: “cmd_off”,
“text”: “Off”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “OffSwitchStatus”,
“Value”: “100”,
“Top”: 40,
“Left”: 50,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “Off”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “0”
}
]
}
},
{
“ControlGroup”: “3”,
“ControlType”: “button”,
“top”: “2”,
“left”: “1”,
“Label”: {
“lang_tag”: “keep_warm”,
“text”: “Warm”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “0”,
“Top”: 120,
“Left”: 50,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “KeepWarm”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “0”
}
]
}
},
{
“ControlGroup”: “3”,
“ControlType”: “button”,
“top”: “2”,
“left”: “0”,
“Label”: {
“lang_tag”: “keep_warm_5”,
“text”: “5 Mins”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “0”,
“Top”: 120,
“Left”: 200,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “KeepWarm5”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “0”
}
]
}
},
{
“ControlGroup”: “3”,
“ControlType”: “button”,
“top”: “1”,
“left”: “0”,
“Label”: {
“lang_tag”: “keep_warm_10”,
“text”: “10 Mins”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “100”,
“Top”: 120,
“Left”: 300,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “KeepWarm10”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “100”
}
]
}
},
{
“ControlGroup”: “3”,
“ControlType”: “button”,
“top”: “1”,
“left”: “1”,
“Label”: {
“lang_tag”: “keep_warm_20”,
“text”: “20 Mins”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “0”,
“Top”: 120,
“Left”: 400,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “KeepWarm20”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “100”
}
]
}
},
{
“ControlGroup”: “4”,
“ControlType”: “button”,
“top”: “0”,
“left”: “1”,
“Label”: {
“lang_tag”: “100_deg”,
“text”: “100 Deg”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “0”,
“Top”: 150,
“Left”: 100,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “Deg100”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “0”
}
]
}
},
{
“ControlGroup”: “4”,
“ControlType”: “button”,
“top”: “0”,
“left”: “0”,
“Label”: {
“lang_tag”: “95_deg”,
“text”: “95 Deg”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “0”,
“Top”: 150,
“Left”: 200,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “Deg95”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “0”
}
]
}
},
{
“ControlGroup”: “4”,
“ControlType”: “button”,
“top”: “0”,
“left”: “-1”,
“Label”: {
“lang_tag”: “65_deg”,
“text”: “65 Deg”
},
“Display”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Variable”: “LoadLevelStatus”,
“Value”: “0”,
“Top”: 150,
“Left”: 300,
“Width”: 75,
“Height”: 20
},
“Command”: {
“Service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“Action”: “Deg65”,
“Parameters”: [
{
“Name”: “newLoadlevelTarget”,
“Value”: “0”
}
]
}
}
]
},
{
“Label”: {
“lang_tag”: “advanced”,
“text”: “Advanced”
},
“Position”: “2”,
“TabType”: “javascript”,
“ScriptName”: “shared.js”,
“Function”: “advanced_device”
},
{
“Label”: {
“lang_tag”: “notifications”,
“text”: “Notifications”
},
“Position”: “5”,
“TabType”: “javascript”,
“ScriptName”: “shared.js”,
“Function”: “device_notifications”
}
],
“sceneList”: {
“group_1”: {
“cmd_1”: {
“label”: “BOIL”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “Boil”,
“arguments”: {
“newLoadlevelTarget”: “100”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “100”
}
},
“cmd_2”: {
“label”: “OFF”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “Off”,
“arguments”: {
“newLoadlevelTarget”: “0”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “0”
}
},
“cmd_3”: {
“label”: “KeepWarm”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “KeepWarm”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
},
“cmd_4”: {
“label”: “KeepWarm5”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “KeepWarm5”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
},
“cmd_5”: {
“label”: “KeepWarm10”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “KeepWarm10”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
},
“cmd_6”: {
“label”: “KeepWarm20”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “KeepWarm20”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
},
“cmd_7”: {
“label”: “Deg65”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “Deg65”,
“arguments”: {
“newLoadlevelTarget”: “100”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “100”
}
},
“cmd_8”: {
“label”: “Deg80”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “Deg80”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
},
“cmd_9”: {
“label”: “Deg95”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “Deg95”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
},
“cmd_10”: {
“label”: “Deg100”,
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“action”: “Deg100”,
“arguments”: {
“newLoadlevelTarget”: “50”
},
“display”: {
“service”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“variable”: “LoadLevelStatus”,
“value”: “50”
}
}
}
},
“eventList2”: [
{
“id”: 2,
“label”: {
“lang_tag”: “iKettle_status”,
“text”: “The iKettle’s status is”
},
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“argumentList”: [
{
“id”: 2,
“dataType”: “string”,
“allowedValueList”: [
{
“Boiling”: “Boiling”,
“HumanFriendlyText”: {
“lang_tag”: “kettle_boiling”,
“text”: “DEVICE_NAME is boiling”
}
},
{
“Docking”: “Stopped”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_docked”,
“text”: “DEVICE_NAME is stopped”
}
},
{
“Charging”: “Charging”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_charging”,
“text”: “DEVICE_NAME is charging”
}
},
{
“Paused”: “Paused”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_paused”,
“text”: “DEVICE_NAME is paused”
}
}
],
“name”: “SimpleStatus”,
“comparisson”: “=”,
“prefix”: {
“lang_tag”: “which_mode”,
“text”: “Which mode”
},
“suffix”: {}
}
]
},
{
“id”: 3,
“label”: {
“lang_tag”: “iKettle_ping_status”,
“text”: “The iKettle’s Ping Status”
},
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“argumentList”: [
{
“id”: 3,
“dataType”: “string”,
“allowedValueList”: [
{
“Online”: “up”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_online”,
“text”: “DEVICE_NAME is online”
}
},
{
“Offline”: “down”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_offline”,
“text”: “DEVICE_NAME is offline”
}
}
],
“name”: “PingStatus”,
“comparisson”: “=”,
“prefix”: {
“lang_tag”: “which_mode”,
“text”: “Which mode”
},
“suffix”: {}
}
]
},
{
“id”: 4,
“label”: {
“lang_tag”: “iKettle_schedule”,
“text”: “The iKettle’s Schedule”
},
“serviceId”: “urn:sharedfunctions-com:serviceId:iKettle1”,
“argumentList”: [
{
“id”: 4,
“dataType”: “string”,
“allowedValueList”: [
{
“Started”: “Started”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_s_started”,
“text”: “Started”
}
},
{
“Completed”: “Completed”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_s_completed”,
“text”: “Completed”
}
},
{
“Interupted”: “Interupted”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_s_interupted”,
“text”: “Interupted”
}
},
{
“Failed”: “Failed”,
“HumanFriendlyText”: {
“lang_tag”: “iKettle_s_failed”,
“text”: “Failed”
}
}
],
“name”: “ScheduledCleanStatus”,
“comparisson”: “=”,
“prefix”: {
“lang_tag”: “which_mode”,
“text”: “Status is”
},
“suffix”: {}
}
]
}
],
“DeviceType”: “urn:schemas-sharedfunctions-com:device:iKettle:1”
}[/code]

You didn’t say what version of UI you are writing this for. I have assumed it is for UI5. UI7 requires a different approach.

I think the problem with the icon is that you are using two different sources and the file names are not the same. Vera determines the name for a variable icon by appending _nn to the base icon file name. This will not work with what you have defined. You need all the files to be in one place and in the form file.jpg, file_0.jpg … file.100.jpg. This is easier if the files are uploaded to Vera in /www/cmh/skins/default/icons.

If your buttons are not animating, it is most likely a problem with the serviceId, variable name or value in the “Display”: section of the control. Do any of the buttons animate?

Thanks
Yes this is for UI5… I can develop for UI7 yet…

I will look at the Display one to begin with:
No buttons animate yet…
Could you give me a simple example that does work?

So I have a button in my JSON file… lets call test and I attach the variable… say… ‘testStatus’

from my implementation file… I think I am then supposed to set testStatus to newloadlevel 100

is that the right tracK?

That sounds about right. Here is the json for one button that does about the same thing. It is the Max from MiLightWU. A click sets LoadLevelTarget to 100. The button changes state when LoadLevelStatus is 100.

{ "ControlGroup": "5", "ControlType": "button", "top": "0", "left": "3", "Label": { "lang_tag": "full", "text": "Max" }, "Display": { "Service": "urn:upnp-org:serviceId:Dimming1", "Variable": "LoadLevelStatus", "Value": "100", "Top": 20, "Left": 335, "Width": 75, "Height": 20 }, "Command": { "Service": "urn:upnp-org:serviceId:Dimming1", "Action": "SetLoadLevelTarget", "Parameters": [ { "Name": "newLoadlevelTarget", "Value": "100" } ] }, "ControlCode": "dim_max" },

Thats exactly what I needed… I am getting confused by downloading loads of others and they have many buttons…

I will try this now and report back…

thanks RexBeckett… I appreciate your time!

ok… I am back… sorry

This is an example of what I call from the implementation file

iKettle_UpdateVar( "CmdStatus", "Boiling" ) iKettle_UpdateVar( "BoilSwitchStatus", 100 ) iKettle_UpdateVar( "OffSwitchStatus", 0 )
So that runs the function iKettle_UpdateVar… Which I know works because my CmdStatus label updates.
In my json file for the boil and off switches - they look like this:

{ "ControlGroup": "2", "ControlType": "button", "top": "-0.20", "left": "2.1", "Label": { "lang_tag": "boil", "text": "Boil" }, "Display": { "Service": "urn:sharedfunctions-com:serviceId:iKettle1", "Variable": "BoilSwitchStatus", "Value": "100", "Top": 40, "Left": 150, "Width": 75, "Height": 20 }, "Command": { "Service": "urn:sharedfunctions-com:serviceId:iKettle1", "Action": "Boil", "Parameters": [ { "Name": "newLoadlevelTarget", "Value": "100" } ] } }, { "ControlGroup": "2", "ControlType": "button", "top": "-0.20", "left": "1.1", "Label": { "lang_tag": "cmd_off", "text": "Off" }, "Display": { "Service": "urn:sharedfunctions-com:serviceId:iKettle1", "Variable": "OffSwitchStatus", "Value": "100", "Top": 40, "Left": 50, "Width": 75, "Height": 20 }, "Command": { "Service": "urn:sharedfunctions-com:serviceId:iKettle1", "Action": "Off", "Parameters": [ { "Name": "newLoadlevelTarget", "Value": "0" } ] } },

So obviously I missed the variable somewhere… but I have tried a few different ways and cant seem to get it right

Do you see the variables change in LuaUPnP.log? If not, there is something not right in your update function.

Have you defined all the variables in the service file? I don’t know if this is essential but I always do and my buttons always work.

the CMDStatus variable is not declared in the S file and it works…

this is what the log shows =

08      02/05/15 12:31:52.598   JobHandler_LuaUPnP::HandleActionRequest device: 533 service: urn:sharedfunctions-com:serviceId:iKettle1 action: Off <0x320f1680>
08      02/05/15 12:31:52.598   JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=533 <0x320f1680>
08      02/05/15 12:31:52.598   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:sharedfunctions-com:serviceId:iKettle1 <0x320f1680>
08      02/05/15 12:31:52.598   JobHandler_LuaUPnP::HandleActionRequest argument action=Off <0x320f1680>
08      02/05/15 12:31:52.599   JobHandler_LuaUPnP::HandleActionRequest argument newLoadlevelTarget=0 <0x320f1680>
08      02/05/15 12:31:52.599   JobHandler_LuaUPnP::HandleActionRequest argument rand=0.5123592298477888 <0x

You should also have a log entry showing the variable changing. If not, then your luup.variable_set(…) is not correct.

Ok…
So to test my logic… I created a simple function

local function 	testVarSet()
			if (SID == nil ) then SID = iKettle_SID end
	
			luup.variable_set(SID, "BoilSwitchStatus", "100", parentDevice)
		end

I tied this to a button and call this function…

and low and behold… You are right… sheesh…!

Thanks mate… again I appreciate all the help… its very kind of you…

Thanks mate... again I appreciate all the help... its very kind of you...

I’m happy to help. Your first plugin is always a struggle. There are so many small things that can stop it working and most of the documentation is rather sparse on details. Once you get one to work, subsequent ones are comparatively easy. :wink: