Im trying to get a Channel from the Exec binding to change the status of an On/Off switch to update and reflect the current state of the device. As someone who is quite new to all of this, I have a couple of questions I cannot seem to find the answer to, after 3 hours reading the documentation and hunting the forums on this topic.
Question 1
My Exec binding Channel uses Netcat, which returns the result 0 for on and 1 for off. The below works and shows an ON button and and OFF button on my site. However, to the left of the buttons, it displays a 0 or a 1.
ITEMS
Number PLAYSTATION âPlaystation 4â { channel=âexec:command:daa779bc:exitâ }
SITEMAP
Switch item=PLAYSTATION mappings=[â0â=âOnâ,â1â=âOffâ]
Is there are simple way, with the above to stop it displaying that 0 or 1 next to the buttons (as below)?
P.S. If I change the item to a switch or string⊠I either get an âErrâ msg on the sitemap webpage next to the button or a â-â dash and the buttons dont update.
Question 2
The next thing I have have tried is to use a rule to update my switch on the main site, but I am struggling to find a working example that will read/convert my 0 or 1, to postUpdate to my PLAYSTATION switch as on or off (or 0 or 1).
Ive tried multiple variations within a rule to notice the change, but none seem to work e.g.
when
Thing "exec:command:daa779bc:exit"
also
when
Item PlaystationExecResult
In the above, Ive tried âreceived updateâ, âchangedâ, âchanged from 1 to 0â etc etc etc
then
PLAYSTATION.postUpdate(ON)
In the then section Ive tried a simple postUpdate (I changed my items file PLAYSTATION to a Switch and changed the siteitems PLAYSTATION a On and OFF mapping). Ive also tried If/Else.
Ive looked at pulling the exec:command:daa779bc:exit into a Val to convert it, but I cant find examples of how to change 0/1 to On/Off.
So my question is, if theres not a simple way to remove the 0/1 as in my first question, is there a rule I can use to update my switch? Something like:
Rule âPS-ONOFFâ
when
Thing âexec:command:daa779bc:exitâ received update
then
if(âexec:command:daa779bc:exit.state.substringâ(0,1) == â0â)
{PLAYSTATION.postUpdate(ON)}
else
{PLAYSTATION.postUpdate(OFF)}
end
Thanks