A few general questions about Device Types

Hi everyone,

Im a basic/average programmer and struggling with some concepts when creating a new device type.

The basic are that I have made a RESTapi for my heating system: Heatmiser Neo and have various operations; mainly on/off and set temp.

My first issue came when using a multiAttributeTile with the type of Thermostat. None of the additional controls seemed to show on the tile which I think is due to a Android bug. No idea when/if it will be fixed. I must admit im struggling with the Documentation on the basic linking of the various components

I have got around this by using a more basic tile and currently struggling with a few things:

  1. Polling. I’m not sure on the best method to check a devices state and set it. Using my example, a Thermostat will have a set temperature which can be adjusted on the device or via smartthings. What would be the best method of ensure smarthings was up to date and then updating the value?
    In my mind you would, upon opening the device in the app or every n mins, poll the device to see it’s set level. Then when you change the level - re read the device’s level. If the set commend work then the level would be changed on the tile to reflect, else it would remain the same.

  2. Reading responses from API calls. Currently I send an command to my API like:
    sendHubCommand(new physicalgraph.device.HubAction("""${method} ${uri} HTTP/1.1\r\nHOST: ${settings.ip}:${settings.port}\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))

How can I read its response? Typically my RESTapi server returns Jason, for example {“CURRENT_TEMPERATURE”: “18.8”, “CURRENT_SET_TEMPERATURE”: “12.0”}, any suggestions in handling it?

  1. Linking tiles action to code. I have the code below for my multiAttributeTile. I cant work out how to intercept the code upon the value change and capture the new value to do something with. The on() off() methods work fine. This is the area im most confused about as I think its a combination of my understanding, documentation and bugs.

multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){ tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821" attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff" } tileAttribute("device.heatingSetpoint", key: "VALUE_CONTROL") { attributeState("zxc", value: '20', action: "setHeatingSetpoint") } }

1 Like