HELP with new device plugin

Hi there,

I’m creating a plugin for a bathtube i own, which is controlled by RS485. I’ve created the state variables on the service file for the plugin, like this:

<stateVariable> <name>Painel</name> <sendEventsAttribute>yes</sendEventsAttribute> <dataType>number</dataType> <shortCode>painel</shortCode> <defaultValue>0</defaultValue> </stateVariable>

and i set the value from 0 to 1 if the device is turned ON, on the implementation file:

<action> <serviceId>urn:micasaverde-com:serviceId:Sinapse1</serviceId> <name>LigarPainel</name> <run> log("Ligando Painel") raSendCmd("ONOFF:1;") luup.call_action("urn:micasaverde-com:serviceId:Sinapse1", "SetPainel", {newPainelValue = "1"}, lul_device) </run> </action> <action> <serviceId>urn:micasaverde-com:serviceId:Sinapse1</serviceId> <name>DesligarPainel</name> <run> log("Desligando Painel") raSendCmd("ONOFF:0;") luup.call_action("urn:micasaverde-com:serviceId:Sinapse1", "SetPainel", {newPainelValue = "0"}, lul_device) </run> </action>

I then created two buttons for this action on the device’s json file, one for ON and one for OFF:

{ "ControlGroup": "1", "ControlType": "button", "ControlCode": "LigarPainel", "Label": { "lang_tag": "panel_on", "text": "Ligar" }, "Display": { "Service": "urn:micasaverde-com:serviceId:Sinapse1", "Variable": "Painel", "Value": "1", "Top": 20, "Left": 100, "Width": 80, "Height": 20 }, "Command": { "Service": "urn:micasaverde-com:serviceId:Sinapse1", "Action": "LigarPainel", "Parameters": [] } }, { "ControlGroup": 1, "ControlType": "spacer", "HorizontalMultiplier": "0.7" }, { "ControlGroup": "1", "ControlType": "button", "ControlCode": "DesligarPainel", "Label": { "lang_tag": "panel_off", "text": "Desligar" }, "Display": { "Service": "urn:micasaverde-com:serviceId:Sinapse1", "Variable": "Painel", "Value": "0", "Top": 20, "Left": 190, "Width": 80, "Height": 20 }, "Command": { "Service": "urn:micasaverde-com:serviceId:Sinapse1", "Action": "DesligarPainel", "Parameters": [] } }

When i click the button, the command is being sent, but it’s not “marked” as pressed. Neither for ON nor for OFF states. It’s like it’s ignoring the variable i’ve created. But it i go to the created device configuration and add a variable with the same name as the state variable, let’s say, Painel, and set it’s value from there, the button get’s “pressed” according to the dashboard created variable value.

What am i doing wrong here?
P.S - I have used the “RadioRA2 Serial” plugin as base for mine, since both are controlled from RS232/RS485 connection and i know the methods for RadioRA2.

Sinapse.zip (5.7 KB)

First, in your device file (D_Sinapse.xml), do not use “micasaverde-com” as the namespace for your service and types. You are hijacking their domain and it’s bad form. Your device type references “plugada-net”… if you own this domain, that’s a better choice. If you don’t own a domain name, I recommend using “sergiobaiao-vera” (e.g. urn:sergiobaiao-vera:serviceId:Sinapse for the service ID). You’ll need to make this change throughout, all references.

Now, the button will only be highlighted if your static JSON control definition includes a “Display” section with a service ID, variable name, and value. You have that, referring to a variable Painel. Following the implementation of the LigarPainel action the button uses, it invokes at SetPainel action, but that action is not implemented. It is defined in the service file (S_.xml) but there’s no implementation (I_.xml). So the variable Painel isn’t being set to 1 to match the static JSON’s requirement to highlight the button. If all SetPainel is meant to do is set the Painel variable value, just use luup.variable_set() directly, don’t invoke an action from another action to do it… that’s not very efficient.