Curl > json command

HI,
Trying to flip a switch on my Zwave hub which doesn’t accept mutt posts, but can be reached through an api call, i need the correct code which i obviously ask your help for :wink: I figured it should be possible through the Rest platform using the restapi, but cant find the correct code, nor documentation to do so.

this is the correct code on the Hub:

curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"<OID>", "prop":"command", "value":"on"}}' http://<hostname_iungo>/iungo/api_request,

and in the graphical coding ui:

15

How could i flip the switch using the dev tool on Hassio , or preferably even by creating a switch in the config/switch/yaml? Selecting the Switch command doesn’t work.

currently, i tried the switch as a mqtt switch, but as explained the won’t do it, since the hub doesn’t accept posts yet. Still for your info the way i defined them do so far:

  • platform: mqtt
    state_topic: “macaddress/powerswitch-zwave/430ba8cf”
    name: “Office”
    command_topic: “macaddress/powerswitch-zwave/430ba8cf/command”
    availability_topic: “macaddress/powerswitch-zwave/430ba8cf/available”
    payload_on: “on”
    payload_off: “off”

thanks for any help to get me on the road here.
Marius

Have you tried using the Resful Switch?

yes! as we speak…thx for your reply!

- platform: rest
  resource: http://myip/powerswitch-zwave/430ba8cf
  body_on: '{"active": "true"}'
  body_off: '{"active": "false"}'
  is_on_template: '{{value_json.is_active}}'

what anything else be needed?

forget about the above, should have been more like this:

- platform: rest
  resource: http://ip-address/iungo/api_request/430ba8cf
  name: Office_rest
  body_on: '{"command": "on"}'
  body_off: '{"command": "off"}'

I get to see the switch, can even toggle it, but it doesn’t change the actual switch and the switched switch switches back to the off state automatically. No error message btw.

So, some progress, but no yet there…
Your suggestions are still very welcome :wink:
Cheers,
marius

Try this… I used the curl command you posted above.

switch:
  - platform: rest
    resource: http://<hostname_iungo>/iungo/api_request
    name: Office_rest
    body_on: '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}'
    body_off: '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"off"}}'
    is_on_template: '{{value_json.is_active}}'

I doubt the is_on_template line is correct. Can you post the results here that you get from running the curl command?

curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"<OID>", "prop":"command", "value":"on"}}' http://<hostname_iungo>/iungo/api_request

great, im rebooting as i type this :wink:

you might be very correct about the is_on_template, it was an uneducated guess of mine, based on practically no knowledge of Json yet. Hoping to learn on the job and form all you magical people on this forum… :+1:

about the curl command: how do i run that? couldn’t find the option in the dev’s bit .

Marius

—edit:
same thing happening: switch is showing as switchable in the frontend, but doesn’t work. Checking in the <> states developer tools, its shows as Off, both when off and on…
ill # the is_on_template first and see what happens

The switch showing the wrong state is likely caused by is_on_template being wrong. When you toggle the switch in Home Assistant does the physical switch change?

To run the curl command, you can SSH to the machine you’re running Home Assistant on and run it from there. When you run that curl command it should toggle the switch.

this is what the curl command returns:

{"ok":true,"type":"response","time":0.0010938079794869,"rv":{"value":"off"},"systime":1510585514,"seq":1,"error":false}

and No the switch doesn’t toggle

ill try another reboot, and be certain the changed switch definition is loaded, (too bad one can only do that by rebooting the host…)

—edit:
both curl commands for on and off seem to work. A bit latency, and the above error stays, ({"ok":true,"type":"response","time":0.078504142991733,"rv":{"value":"on"},"systime":1510586342,"seq":1,"error":false}) but the switch switches!
Definite progress… Now how to get that into the front end and kill the error.

Cool. That’s a promising result. Can you try this?

switch:
  - platform: rest
    resource: http://<hostname_iungo>/iungo/api_request
    name: Office_rest
    body_on: '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}'
    body_off: '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"off"}}'
    is_on_template: >-
      {%- if value_json.rv.value == 'on' -%}
      {{ true }}
      {%- else -%}
      {{ false }}
      {%- endif -%}

nope… very sorry. feel so stupid here.

same behavior: switches shows as off, while being on.
clicking the switch in the fronded, it slides shortly, a small popup pops up stating Turned-on Office_rest3 and the switch slides back. No state change of the actual switch

37

—edit:

wait a minute! something is happening, When i put the switch in Off position manually, or through the Hubs interface, i can switch it on with the above switch in the front-end. Cant put it off again though :wink: Which seems appropriate since it keeps stating it switched the switch On. still getting there it seems.

Also I’ve had this once or twice: 36
seemed like a proces was going on (toggling the switch), but never finished.

Hrm, sounds like the is_on_template might be the culprit. Can you do the curl commands again and show me the command that turns the switch on along with the response you get? Then do the same to turn it off, and sent me the curl command along with the response.

here goes:
actual switch in on position:

curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"off"}}' http://my.ip/iungo/api_request

result:

{"ok":true,"type":"response","time":0.074003877991345,"rv":{"value":"off"},"systime":1510603249,"seq":1,"error":false}

actual switch is now off:

curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}' http://my.ip/iungo/api_request

result: nothing happens…
{"ok":true,"type":"response","time":0.0011875630007125,"rv":{"value":"on"},"systime":1510603374,"seq":1,"error":false}
silly, now i cant switch in on…
i checked in the Zwave hubs interface: the switch was showing a green switch (signaling being on) but didn’t show any power consumption which is correct, since it wasn’t really switched on. Ive put it off in the hubs interface, and now am able to actually switch it on with

curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}' http://my.ip/iungo/api_request

same result:
{"ok":true,"type":"response","time":0.075847724016057,"rv":{"value":"on"},"systime":1510603550,"seq":1,"error":false}

if i try to turn it off again, i have the same intermittent results…something must still be amiss, either it doesn’t always stick, get through to the Hub, or on the Hub the states aren’t set correctly…

Maybe running a z-wave repair would help?

thats what i thought, so I’ve rebooted the hub and all is running again. Need some time to repopulate and build the devices.

in the mean time, I’ve setup switches for a few more, and this is whats showing in the frontend right now:
55

Ive tried the individual switches, but they still behave the same: nothing happens to the real switches, and though the dark filled flash seems to indicate the switch is available, the switch in the right side stays Off, no matter the actual state:

Ok, I re-read the RESTful Switch docs, and realize I was mistaken on how is_on_template works. It doesn’t look at the response from the post, it actually issues a GET request. Do you know how to get the switch status using a GET request using curl?

should be able to translate this into Curl:

10

curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"430ba8cf", "prop":"state"}}' http://ipaddress/iungo/api_request

does it

result:

{"ok":true,"type":"response","time":0.00046877599743311,"rv":{"value":"on"},"systime":1510686946,"seq":1,"error":false}

Ok, the issue using RESTful Switch is that there is no way to define the payload for the is_on_template, which in your case is different. Perhaps the command line switch is a better option. Give this a try:

switch:
  platform: command_line
  switches:
    office_rest:
      friendly_name: Office REST
      command_on: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}' http://<hostname_iungo>/iungo/api_request
      command_off: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"off"}}' http://<hostname_iungo>/iungo/api_request
      command_state: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"430ba8cf", "prop":"state"}}' http://ipaddress/iungo/api_request
      value_template: >-
        {%- if value_json.rv.value == 'on' -%}
        {{ true }}
        {%- else -%}
        {{ false }}
        {%- endif -%}

o wow, ill try that immediately.!
if we’re (i…) going this route, maybe i could combine these api calls with a call on the power and usage setting too, and display these in a badge somehow, like on GitHub - andrey-git/home-assistant-custom-ui: Custom UI elements for https://home-assistant.io

anyways, first ill give these a try.
bebacksoon.
Marius

this is going somewhere indeed!
I started in the actual On position, and the sensor showed Off though, and that worried me somewhat,

Ive put the switch off through the hub, et voila, the switch works and doesn’t slide back. It even displays a yellow flash when on, and a black flash when off (at the moment with the grey circle, i don’t know what that means?:

44
01

so its much better, but the initial state check was still incorrect. Also sliding it Off sometimes needs a second try, for which i need to slide it back on (…)

the pop up is correct now, displaying the correct action :wink:

Cheers,
Marius

check this!

39

this is rather a great start, thanks to @NotoriousBDG !

maybe some extra State-checking, and then we’re off for further enhancement. First id love to add the power and usage per switch. Ive already managed to sensor these through mqtt, and fear somehow that trying to Get these values per Api call might burden the wave-host too much. What do you reckon?

Also, id like to learn how to call these switches in a rule.

Cheers,
Marius