Questions about changing the status of a Switch's slider

I’m using OH2 on a RaspberrPi. I have configured a switch in OH2 through which I can toggle my patio light. This works just fine. The light icon changes from yellow to gray anytime the light goes from on to off, and vice versa, perfect. Now, I also have a python script, controlled by a light sensor and it turns the light on at dusk, but the when this happens, the state of the switch in OH2 (PaperUI oriOS) does not reflect the new state. Specifically, I’d like the like icon and the switch’s slider to reflect the state of the patio light. How can I make this happen, if at all? Here are my configs:

sitemap:
Switch item=Patio_Light

items:
Switch Patio_Light “Patio Light” [channel=exec:command:e3c40992:exit]

I have a Thing configured in OH2 as:
Patio_Light_Status -> exec:command:e3c40992:exit

It runs a script that checks the state of the light every 5 seconds and its exit value is a Number (0/1). There is a log statement within the script that logs to the system console and I see that it is running and exiting with the exit status, but the state of the Patio_Switch never changes in PaperUI or the iOS app. I have tried using various combinations of mappings, e.g mappings=[On=1] in my items file to no avail. Can I make this work? If so, how?

I found this example in another script:
’/usr/share/openhab2/runtime/bin/client send frontdoorTriggered ON’

I’m going to try this when I get home this evening. I have a rule which gets executed when I tried the switch through OH2. The script currently communicates directly with the switch via BT and I’ve been trying to get the OH2 interface to update when the switch is triggered. I the commanline above provides the best way to accomplish this task.

Does this make sense?
Thanks

That makes sense. Other options is to have your python script make the HTTP call to the REST API to update the switch or report the state of the switch via MQTT.

Thanks for the reply. I’ll start simply for now. I’ll be looking at mqtt once I get more comfortable with OH2.

“My Break-Dancing days are over, but there’s always the Funky Chicken” – The Full Monty

I find that this command
/usr/share/openhab2/runtime/bin/client requires authentication. This is a problem as this command needs to be executed from a script. Sort of defeats the purpose of home automation. I can’t find any documentation on how to setup a user to automatically login. I did find a post that said this authentication was removed for the GA release. I installed my OH2 from Bintray. I have version 2.0.0 Release Build as reported via the console. What is the mechanism for upgrading, if thats necessary to fix this issue?
Thanks

One way would be to use ssh and a pub key to access the console:

But… it’s better to use the REST API as Rich said to send a command to an item using an external script
Or… integrate the light sensor in OH2 and use a rule to fire the command to the light

I actually need to run this from the same machine as OH2. In any case, I found a short term solution in this post:
http://tinyurl.com/ybtyvw3k

I just use Expect to handle the prompts for me. I’ll be looking into more “native” solutions later, but for now, this will do.
Thanks everyone for the replies.

1 Like