Curl > json command

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.

Yes, that is possible, but not very nice…check tester and multi-functional below:

55

It takes out the toggle, which i could live with, (replaces it with an active and inactive lightning bolt) but it stops communication from the switch to the frontend. Iow, one can switch from within HA successfully, but if the switch is toggled manually on the hardware-switch, it doesn’t show in the front end.

Which leads me back to the question if we can adjust the polling time of the state command_line?

to be complete, this is the code right now, i left the logical test intact hoping it would see it, but i think it isnt used now since ive taken out the State command:

    sw_tester_cl:
      friendly_name: 7 - Tester
      command_on: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"4e6eeb01", "prop":"command", "value":"on"}}' http://192.168.xxx.xxx/iungo/api_request
      command_off: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"4e6eeb01", "prop":"command", "value":"off"}}' http://192.168.xxx.xxx/iungo/api_request
#      command_state: >-
#        curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"4e6eeb01", "prop":"state"}}' http://192.168.xxx.xxx/iungo/api_request
      value_template: >-
        {%- if value_json.rv.value == 'on' -%}
        {{ true }}
        {%- else -%}
        {{ false }}
        {%- endif -%}

    sw_multi_functional_cl:
      friendly_name: 8 - Multi Functional
      command_on: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"7b4d9b1b", "prop":"command", "value":"on"}}' http://192.168.xxx.xxx/iungo/api_request
      command_off: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"7b4d9b1b", "prop":"command", "value":"off"}}' http://192.168.xxx.xxx/iungo/api_request
#      command_state: >-
#        curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"7b4d9b1b", "prop":"state"}}' http://192.168.xxx.xxx/iungo/api_request
      value_template: >-
        {%- if value_json.rv.value == 'on' -%}
        {{ true }}
        {%- else -%}
        {{ false }}
        {%- endif -%}

ive tried this workaround by creating binary sensors based on their usage, and show these in the frontend as extra-badges:

02

As you can see it gets very crowded, and yet, the switches report incorrectly. Binary sensor and usage show Off or zero , while the bolt is highlighted and the multi_functional icon is hot.

Back to original quickly :wink:

Thanks,
Marius

That’s expected because you’ve removed Home Assistant’s ability to track the state of the switch.

The docs don’t mention it and I don’t see anything in the code that suggests it’s configurable.

or posts crossed…

As you can see ive been trying the binary sensor. That seems to update in a more relaxed frequency, implying the system should be able to take it easier…

Would this be a @balloob question, or where else should i post this, you know?

Thanks,
Marius

You could use Template Switch - Home Assistant to combine your command line switch and your binary sensor into a switch that infers its state from power usage. It still won’t be accurate if the switch is on with no load attached.

HI @NotoriousBDG

yes!
I believe you pointed me to this before, but this was in the beginnings of my HA travels, and i simply couldn’t make coffee of it.
As i have a little deeper understanding now, i do see the caveat you point to, as that is exactly what is happening already with the test setup ive got . Switch is on, no load though so binary shows off…

Second thought i would have is if this testing and cross templating isnt even more prone to processor load than the current command_line switch, which is at least dead-accurate…

i feel we need something like the delay_off option for the command_line switch, just as with the binary’s:

tester:
  friendly_name: "Tester:"
#      delay_off:
#        minutes: 1
  value_template: >-
    {{ states('sensor.tester_actueel')|float > 0 }}

this is working alright, with the exception of your 0-usage issue:

33

btw, as you can see i;ve configured the binaries to need to be bigger than 0. As these happen to be fibaro plugs, the use up to 0,5 watt even when idle/off. Their meter doesn’t show…

Cheers,
Marius

Can you clarify the processor load issue you’re having? I thought you were saying your z-wave hub couldn’t handle the load, but now it sounds like you’re talking about your Home Assistant machine.

True, but i suspect it’s a bit of both:

30

I can see the RAM and Disk usage of the hassio Pi going up, (processor actually quite low…sorry for that mixup) and the system seems to get slower and slower, and i get closed tabs because of power/memory overloads in my browser window more often.


Hadn’t seen those before…

Thats why im trying to reduce unnecessary activities as much as possible. Example: im using a summary.py script thats runs on each change of a set of entities states. But it runs far more often than the actual state changes. It seemed to be triggered by those command_line state polls, which in fact are unnecessary for that summary.py. Ive change the summary to use a set of mqtt sensor-derived binaries, and things are much better on that level. Still, the state command line triggers every 15 seconds or so.

My zwave hubs publishes all events on MQTT, and then receives these command_line polls from HA. I believe there’s a fair bit of prioritizing issues between the 2, and every now and then get the max- pending error. Im not sure if thats from the Hub or the sending HA instance yet…

all in all,
hope to reduce any superfluous activity on both sides…
Marius

If you can get switch state via mqtt, you could use that to create a binary_sensor and use it for state in the template switch.

18GB disk space used sounds like a lot. You might want to check your database to see if you’re storing more history than you need…

of course! duh. Thank you! no querying the Zwave hub required, just subscribing to the published events…

check this:
regular mqtt sensors reading property: State

binary sensors reading the same property: State

this might even be better than the command_line version, since we can now use the Qos=1, making sure the message is red and delivered. Before, quite often the command wouldn’t stick because of several intermediate issues (timing, availability, sequence etc etc)

I am still a bit puzzled how to combine these into one template switch though, please give me a nudge:

this is the code i use now for a regular mqtt sensor:

- platform: mqtt
  state_topic: 'mac_address/powerswitch-zwave/4e6eeb01/state'
  name: "Tester state"
  unit_of_measurement: "State"
#  value_template: "{{ value | round(2) }}"

the code for the binary sensor:

- platform: mqtt
  name: "Tester state bin"
  state_topic: 'mac_address/powerswitch-zwave/4e6eeb01/state'
  payload_on: "on"
  payload_off: "off"
#  availability_topic: "home-assistant/window/availability"
#  payload_available: "online"
#  payload_not_available: "offline"
  qos: 1
  device_class: plug
#  value_template: '{{ value.x }}'

And the current Command_line Switch:

sw_tester_cl:
  friendly_name: 7 - Tester
  command_on: >-
    curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"4e6eeb01", "prop":"command", "value":"on"}}' http://192.168.xxx.xxx/iungo/api_request
  command_off: >-
    curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"4e6eeb01", "prop":"command", "value":"off"}}' http://192.168.xxx.xxx/iungo/api_request#      command_state: >-
  command_state: >-
    curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"4e6eeb01", "prop":"state"}}' http://192.168.xxx.xxx/iungo/api_request
  value_template: >-
    {%- if value_json.rv.value == 'on' -%}
    {{ true }}
    {%- else -%}
    {{ false }}
    {%- endif -%}

trying this preliminary code for starters:

- platform: template
  switches:
    switch_template_tester:
      friendly_name: "Tester"
      value_template: "{{ is_state('binary_sensor.tester_state_bin.state', 'on') }}"
      turn_on:
        service: switch.turn_on
        data:
          entity_id: switch.sw_tester_cl
      turn_off:
        service: switch.turn_off
        data:
          entity_id: switch.sw_tester_cl

Thanks!

Im not sure where to start.
my home-assistant_v2.db is only 111,5 mb. I have MariaDB installed but just admit i don’t have any idea where it is stored on the flash card…
Other than a few backups (max 3gb) and the system files, i wouldn’t know where to find the space-hogs.

Ive tried to limit the logging by entering the following in my logbook.yaml, so it doesn’t even log the sensors yet…:
include:
domains:
- script
- notify
- switch
entities:
- device_tracker.phone1,2,3,4,5,6

HI @NotoriousBDG,

Your advise was very appreciated, ive made the switches based upon the above, with a slight change in the state sensor:

    sw_tester_template:
      friendly_name: "7 - Tester"
      value_template: "{{ is_state('binary_sensor.tester_state_bin', 'on') }}"
      turn_on:
        service: switch.turn_on
        data:
          entity_id: switch.sw_tester_cl
      turn_off:
        service: switch.turn_off
        data:
          entity_id: switch.sw_tester_cl 

Customized them a bit for eye candy and functionality thanks to @andrey’s awesome customize-ui and here goes:

to the left the now truncated Command_line switches with the get state taken out, hence the bolts instead of the toggle. To the right the new template switches, working properly as they are.

My logfile has calmed down like you can’t imagine! :+1:

no more state polling every 15 seconds, and the @mviezzer 's adjusted summary.py has calmed down also :wink:

only thing bothering still is the Hassio specs growing out of hand even further…

15

anyways, thank you very much!
Marius

Very cool. You can hide the curl switches and binary_sensor in customize.yaml to get them out of your way.

For MariaDB, you can control size by setting purge_interval and purge_keep_days in the recorder component. You can also exclude any entities that you don’t care about tracking.

Personally, I use InfluxDB and Grafana for graphing historical data and limit MariaDB to 1 day because the MariaDB database gets huge fast.

To figure out what’s using all that disk space, you can ssh into the host and look around by following steps shown at Debugging the Home Assistant Supervisor | Home Assistant Developer Docs. The place you want to check out is /resin-data.