I have a python script that contains the following:
x = eg.event.payload[1]
try:
response = requests.post(
'http://192.168.1.190:8123/api/states/sensor.hem_theperiod',
headers={'x-ha-access': 'mypassword', 'content-type': 'application/json'},
data=json.dumps({'state': x, 'attributes': {'hidden': 'true', 'friendly_name': 'the period'}}))
except:
print ("%%%%%% HA Connection Error %%%%%")
I have tried to convert this to groovy and have not had any success. Here is the last of many attempts
def params = [
uri: "http://192.168.1.190:8123",
path: "/api/states/sensor.hem_theperiod",
headers: ['x-ha-access': 'mypassword','content-type': 'application/json'],
data: ["'attributes': {'hidden': 'true', 'friendly_name': 'the period'}, 'state': '4'" ]
]
log.debug "Calling HAS"
httpPostJson(params) { resp ->
resp.headers.each {
log.debug "${it.name} : ${it.value}"
}
log.debug "response contentType: ${resp.contentType}"
}
log.debug "HAS called. $response"
This and many other attempts have failed. I am looking for some help tho get the above python code converted to groovy,
Thanks in advance