(All values are bytes)
I wanted to define sliders to chose between 0 = off, 1 = auto, 2 =on.
Lacking radio buttons in thinger.io
But upon defining the slider, I got:
and no way to get to the individual values.
Has anyone got an idea how to come to the values level?
Finally I got a working, but it is quite an awful solution:
Inputs do not seem to be definable as multiple resources.
You must define one resource per switch.
…and be tricky if you need to define a tri-state switch.
Create a slider from 0 to 2 in steps by one.
Define a description OFF___________Auto___________ON
that is as large as your field.
The code behind **each** switch is:
thing["tris1.1"] = [](pson & in, pson & out)
{
if (in.is_empty())
{
in = Tasmo1.Relay1Out;
} else {
Tasmo1.Relay1Out = in;
}
out = Tasmo1.Relay1Out;
};
changing the values for the resource and the byte variable.
And -of course- write the logic to override the automatic value, if the tri-state switch is on 0 or 2.
Quite a lot of work for a simple switch…
I believe that the Form Property resource available only for PRODUCTS would help in this case.
I have been studying this same issue.
Define operating states for the device Manual, Automatic… And relay states (off/on).
Apparently, the way is to develop a form linked to a device/Product property. I have already achieved this successfully. It remains to test the consistency of this approach with the command to turn the relays on and off via the device API in a consistent and reliable way.
Products are not included in maker accounts.
So I had to use the slider to define my tri-states as bytes.
But it works reasonably well:
I used bytes instead of booleans.
0= force to off
1= leave as is
2= force to on
And the feed back is
0= off
2= on
(1=error)
byte Relay1fb; // Feed-Back
byte Relay1cmd = 1; // 0 = 0ff 1 = Auto 2 = On
in setup()
thing["tris1.1"] = [](pson& in, pson& out) {
if (in.is_empty()) {
in = Tasmo1.Relay1cmd;
} else {
Tasmo1.Relay1cmd = in;
}
out = Tasmo1.Relay1cmd;
};
in loop()
void processDigitalOutputs() {
if (Tasmo1.Relay1cmd == 0) {
mqtt.publish("cmnd/thinger1/Power", "OFF");
}
if (Tasmo1.Relay1cmd == 2) {
mqtt.publish("cmnd/thinger1/Power", "ON");
}
You may of course replace the “mqtt.publish…” lines with every other way to control the relays.
For me it was important to be able to get the tri-state function, since the controlled devices have a built-in schedule function which I want to keep or override on user choice.
I actually need two (or three) widgets for each relay.
The first one is the feed-back
The second one is the control mode
The optional third one is just a passive text, with a link to the schedule control page as overlay: