Curl > json command

Does the switch state eventually update if you leave it alone for a minute or 2 after toggling the switch?

not sure, didn’t wait that long yet…
im experiencing a bit of trouble on the Hub during this experimenting and communicating with HA. Hope thats purely coincidental, and trying to figure out with the dev’s.

still, both fronten-interfaces seem to display the same: switches in the correct position, the timers set their switches this morning, and that was nicely displayed on the HA switches too.

Too bad the real hub wasn’t reacting in the way it is supposed to . seems the wave controller is out of order somehow.

let me ask please: when does this command-line definition check its status? is it a constant polling, like the mqtt subscribe, or does it only act upon state-change. Im a bit confused how it could do the latter, without constant polling of that state. I ask specifically because i don’t want to burden the wave controller with constant requests.

secondly: how do i get to display the values of power and usage on these switches? The following properties are available:

I believe the command_line switch polls every 60 seconds. I thought you already had power and usage working via mqtt. If not, that’s probably the best route for them.

yes i have set up power and usage working correctly over Mqtt. Ive asked the dev to implement the retain value, and that will soon be realized i hope, resulting in no more Unknown’s.

dev’s told me they rather not have api calls for streams querying the values. so i’ll best leave it like it is, values are collected by subscribing to the mqtt events the hub publishes, and the switch states can be controlled through the efforts above!

Please give me another nudge towards combining these in a single representation in the frontend. Ideally id have one item per switch, with a flippable switch and power and usage updated continuously.

my mqtt definitions for the sensor:

- platform: mqtt
  state_topic: 'macaddress/powerswitch-zwave/430ba8cf/usage'
  name: "Office actueel"
  unit_of_measurement: "Watt"

- platform: mqtt
  state_topic: 'macaddress/powerswitch-zwave/430ba8cf/power'
  name: "Office totaal"
  unit_of_measurement: "kWh"

and the switch:

sw_office_cl:
      friendly_name: 6 - Office
      command_on: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}' http://ip/iungo/api_request
      command_off: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"off"}}' http://ip/iungo/api_request
      command_state: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"430ba8cf", "prop":"state"}}' http://ip/iungo/api_request
      value_template: >-
        {%- if value_json.rv.value == 'on' -%}
        {{ true }}
        {%- else -%}
        {{ false }}
        {%- endif -%}
1 Like

Adding support for retain would definitely be helpful. You may want to ask them to make switches subscribe to a command topic so you can toggle switches over mqtt.

I believe adding power and usage as attributes on an entity requires writing a custom component. Also, if you make them into attributes, their values won’t be stored over time, which means you wouldn’t be able to create graphs with them. I think you’re better off leaving them as separate sensors.

I’d suggest looking at Groups as a means of making the switch, power, and usage entities show in a meaningful order in the UI.

sure, i will most certainly.
Still, for my education, how would a command_line statement look if one needs the value of power and usage, and display it in the frontend?

This must be a valid curl, but don’t just yet understand how to display the 'value’s the frontend:

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

resulting in:
{"ok":true,"type":"response","time":0.00075004099926446,"rv":{"value":0.4661},"systime":1510783275,"seq":1,"error":false}

in Watt

and

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

resulting in:

{"ok":true,"type":"response","time":0.00046877499698894,"rv":{"value":6.4},"systime":1510783360,"seq":1,"error":false}

in kWh

sensor:
  - platform: command_line
    name: 430ba8cf Power
    command: >-
      curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"430ba8cf", "prop":"power"}}' http://ip/iungo/api_request
    value_template: {{ value_json.rv.value }}
    unit_of_measurement: "W"

  - platform: command_line
    name: 430ba8cf Usage
    command: >-
      curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"430ba8cf", "prop":"usage"}}' http://ip/iungo/api_request
    value_template: {{ value_json.rv.value }}
    unit_of_measurement: "kWh"

thank you!
That worked. Had to add the quotes to the value_template: "{{ value_json.rv.value }}" but the rest was just perfect.

As we expected it doesn’t give a continuous stream though, and after testing i had to decide to indeed measure the switches’ power and usage with the mqtt setup, and command them with the command-line switch.

Had a whole lot of issues on the Zwave side though, so am glad I’ve got it all back up and running today.

Didnt have a chance to make it look prettier yet.

cheers,
Marius

1 Like

a further optimization would be the presentation of the value. Some now are either too precise after the decimal, or not precise enough, rounding all to 0…
Hope forum etiquette allows me to elaborate in this topic (wouldn’t want to be kicked off again…:wink: )

check:
175106

with the above example, i would love to have the current Gas to be displayed as 0,082 as in the graph instead of 0, and the solar panels rounded at 2, max 3 after the decimal.

The value template could be used for rounding with the option | round 2 but we’re talking mqtt sensors here defined as follows, without a template:

- platform: mqtt
  state_topic: "mac address/energy-solar-sdm630-modbus/f339a2fb/solar"
  name: "ZP Solar"
  unit_of_measurement: "Watt"

how would i proceed best?
Thanks,
Marius

You can still use a value_template on an mqtt sensor to do the rounding.

maybe you can help, no matter what i try, i get an Unknown in the frontend, error logs don’t really help…
It still is somewhat of a quest to find out what object parameters are available, and/or, as in this case, which can/need to be used in the json.

It’s easiest to use the Templates tool under Developer Tools to test out your template before adding it to your config. Using your example above, you can paste the code below into the Template section and it should return 6.4. You can replace the json with whatever json you want to process, then adjust the last line to verify your’re parsing is correctly.

{%- set value_json=
  {"ok":true,"type":"response","time":0.00046877499698894,"rv":{"value":6.4},"systime":1510783360,"seq":1,"error":false}
-%}

{{ value_json.rv.value }}

You can also check out https://home-assistant.io/docs/configuration/templating/ for some additional examples.

well thanks @NotoriousBDG, im trying, but please indulge me…
I don’t reallyunderstand what to do here.

Ive got
- platform: mqtt
state_topic: “mac address/energy-solar-sdm630-modbus/f339a2fb/solar”
name: “ZP Solar”
unit_of_measurement: “Watt”

and id like the output of Watts to be rounded at 2 figures after the decimal.
I fail to understand completely how your json does that… sure it gives 6.4, but thats what you instruct it to do by stating {'value":6.4} don’t you?
How does this take the outcome of the sensor into account and round it?
Cheers,
Marius

Hrm, I assumed you were talking about the command line switch because you mentioned json. To round the mqtt sensor value to 2 digits, try this:

sensor:
  - platform: mqtt
    state_topic: "mac address/energy-solar-sdm630-modbus/f339a2fb/solar"
    name: "ZP Solar"
    unit_of_measurement: "Watt"
    value_template: "{{ value | round(2) }}"

thats it, thank you very much, I’m sure I’ve tried this, at least coming close to it… must have been the syntax thats still not 100% clear to me, how simple this must look to you. The thing is, the cookbooks do show wonderful examples, but isn’t a real manual in using json and hassio syntax.

before:
57

after:
37

i have another sensor, always displaying 0. it sense the gas usage , once per hour, and that of course is measured in m3 gas. but actual usage is far below that per measured time. lets say 0,02. How to display that, instead of the 0?
I would have expected to show up, since all the other sensors show with 12 figures after the decimal, but it doesn’t .

Cheers,
Marius

I’m not that familiar with gas measurement, but m3 sounds like an instantaneous measurement that only registers a non-zero value when gas is being consumed rather than a cumulative one that shows how much gas you’ve used in the last hour (m3/h). If that’s the case and you’re looking for gas usage over time, you could potentially use the Statistics Sensor to perform the sum over the last hour.

----edit----
not correct after all i guess. It appears to be a measurement of the last hour, measured once each hour.

check this graph, of which only the peaks are to be read, the connecting lines are irrelevant:

31

im trying to figure put the statistics sensor, but of course this is also tricked into thinking the intermediate values are relevant…

ive set it up to have a max age of 60 minutes , ut might have to change that, or some other variables?

- platform: statistics
  entity_id: sensor.gas_actueel_verbruik
  icon: mdi:fire
  max_age:
    minutes: 60
  unit_of_measurement: "/m3"

cheers,
Marius

yes thats correct, I’ve also got a cumulative sensor that measures the total gas usage over time. No day settings or the likes.
I will try the statistics sensor, thank you. Had not seen that before.
Cheers,
Marius

@NotoriousBDG just to let you in on the results so far, see this thread:

1 Like

HI @NotoriousBDG!

Back again…
Please help me with this if you could: the command_line switches poll for state every 20 seconds or so, at least thats what i see when i tail the log.
can we change that in the config anywhere: I only need these to poll on demand really, or at least only when the switch is flipped.
Or would there be any other reason to poll this often? I do have my sensors showing the power usage, so no need to check if they’re on or not, i can see that in the usage.

If the above wouldn’t be possible, maybe lower the intensity to once or twice per minute would already be a step forward to easing up on the system…

Wondering why we need the state in the first place, can’t we just leave those out, and only declare the on and off command?

Cheers,
Marius

You should be able to remove command_state because the docs (https://home-assistant.io/components/switch.command_line/) says it’s optional.