[SOLVED] Updating state of contact using rest/python

Been struggling with this for the fast few hours and don’t seem to be getting anywhere.

Read on the forums someone had a similar issue as was advised to use a PUT rather than a POST.

I’ve tried that and still having issues.

Items:

Contact Door_Garage “Garage Door: %s” (Doors)

Python script:

connection =  httplib.HTTPConnection('openHABianPi.home:8080')
body_content = 'open'
connection.request('PUT', '/rest/items/Door_Garage/state', body_content)

OH2 Error:

Received HTTP PUT request at ‘items/Door_Garage/state’ with an invalid status value ‘open’.

Getting the same result with closed

You are right in thinking that PUT works for contact items but POST does not, although I’m not sure why. The request is case sensitive, try ‘OPEN’ and ‘CLOSED’.

Edit: Reason why POST doesn’t work: POST is a command to an item. Since a contact is a sensor, not an actuator, you cannot command a sensor to close. However, you can update its status (which is what PUT does).

1 Like

Thanks, you are right. Its case sensitive doh! :slight_smile:

OPEN/CLOSED did the trick.