2021.9.0: More energy, USB discovery, template ❤️

Is it possible to add state_class: total_increasing to the REST sensor?

I’m trying to add data from my smart meter to the energy dashboard (which is captured by CEMM made by cedel and has a local open API). I use the REST sensor for this. I’m able to add the numbers to the dashboard, but adding ‘state-class’ to the sensor results in errors.

My current code for the T1 sensor:

- platform: rest
  resource: http://192.168.XXX.XX/open-api/v1/p1/realtime/
  method: GET
  name: 'Stroomverbruik laag tarief - T1'
  value_template: '{{ value_json["data"].t1[1] | round(2) | float }}'
  device_class: energy
  unit_of_measurement: kWh
  scan_interval: 600

Maybe I can change the value using a template of some sorts but that part I don’t really understand (yet). Adding support for the state-class variable to the rest sensor seems to me like a great addition. But maybe I’m simplifying things… not an IT-background :slight_smile:
Any other tips are welcome ofcourse.

Support this idea here:

image

Both options were originally proposed in the mockups, choice is always better. :slight_smile:

It has to be optional to use either kWh or cubic metres i think.

Personally I buy my LPG in 9kg bottles, and people who have more accessible houses get it delivered in 110kg bottles. So there we have another alternative. :slight_smile:

If you first run a select for example for one specific reading then you see what will be deleted. If you see the data which need to be delete just change “SELECT *” with “DELETE”

one row:

SELECT *
FROM "statistics"  where metadata_id='25'
and start like '2021-09-05 11:00%'

Or for all readings for a date …start like ‘2021-09-05 %’

And if you want to use a nested query:

SELECT *
FROM "statistics" where metadata_id in (select id from statistics_meta where statistic_id ='sensor.steca_energy')
and start like '2021-08-06 16:00%'

I see this, not quite the error you have. HA Supervised with Bullseye.

[03:05:53] INFO: Please be patient, this might take a few minutes...
[03:07:23] INFO: Installed Home Assistant 2021.9.4
[03:07:23] INFO: Making a copy of your configuration for checking...
[03:07:28] INFO: Checking your configuration against this version...
[03:12:21] INFO: Configuration check finished - no error found! :)
s6-svscanctl: fatal: unable to control /var/run/s6/services: supervisor not listening
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

And in the supervisor log…

21-09-07 03:05:51 WARNING (SyncWorker_4) [supervisor.docker.interface] Can't grep logs from homeassistant/amd64-addon-check_config: 409 Client Error for http+docker://localhost/v1.41/containers/1aa7edf215dfe7e56e03268da49f47fe97d677ea069544fd53107489dc215443/logs?stderr=1&stdout=1&timestamps=0&follow=0&tail=100: Conflict ("can not get logs from container which is dead or marked for removal")

Yes, I consume a volume.
At least in Germany you pay for kWh. This ist calculated by the supplier.

Home Assistant forces me to use a volume sensor for gas. This way, the consumed energy is not respected. Therefore I suggest to implement an alternative sensor in kWh.

OK finally figured this out and it’s pretty insane. Apparently long term statistics database tables have problem with “μ” sign. Two sensors that had their state_class: “measurement” output in μg / m³ and µS/cm were causing database errors. When I set them to state_class: “none” everything is back up again. None of the energy stats are lost in the process…all working normal :smiley:

That sounds like the problem I had with the sensors saying they changed from EUR to GBP, I had to edit the DB to fix it.

Glad you got it sorted, I need to look into getting my gas fed in.

Do you mean for example.

Pond pump is a known “100w” so if the pump is on record the 100w for however long it is on into an integration sensor to get kWh you can then use in the energy panel for example.

There is probably an easy way to do it in the yaml but I use node red for most things, you could do something like this.

image

Grab the state of the plug on/off then use a change node

image

If it is on it will output 100W, if it is off it will output 0W, then feed that into a new pond pump power entity that will end up in HA.

You can then feed that new sensor into the integration component to create your pond pump energy in kWh.

1 Like

I don’t want to measure it as it is mostly constant anyways. I am looking for something like https://github.com/bramstroker/homeassistant-powercalc just less sophisticated and with HA core functionality preferably.

Exactly what I am looking for, just with HA core functionality :wink:

@jmtatsch

Make a template sensor outputting a numeric value (watts) based on the state of the appliance.
Then use that template sensor as the source for an integration sensor

{%if is_state('light.garage','on') %}
  100
{% else %}
  0
{% endif %}
2 Likes

I have solar power and battery. measuring all the inputs and outputs, but via Modbus and created my own enteties. Would like the support to add wich sensor I want to the energy panel

Using a template sensor you can add whatever you like as long as it meets the correct criteria.

Does it measure power, energy or both.

Watts, Wh or kWh.

I have a solar sensor for production in power (watts) - feed that into a integration sensor to create a kWh energy sensor.

I have a sensor for total house consumption in power (watts) - fed that into a another integration sensor.

Basically what ever you have got sensor wise you need to ensure you have or can create energy sensors likely all in kWh to make it easy.

If you post what one of your sensors looks like people should be able to help

I have these sensors, maybe some more:

o that is interesting, looking for an estimate on my ‘unmeasured devices’ mysel’ and using a template for now subtracting the measured devices from the total usage. which is absolute of course, but this could be interesting on a per device level indeed…

thanks for the link

Just to make sure I have got this right.

1st looks like export to grid, do you have a export FIT tariff you get paid for export ?
2nd looks like how much solar you are generating
3rd looks like battery % (Do you have sensors for wh in and out of battery or just SoC charge as %)
4th looks like consumption ie how much your house is using

So you can make 3 sensors from this to plug into the energy panel.

export
production
consumption

This is the guide here

In your configuration.yaml under your sensor: section if would look something like this;

sensor:
  - platform: integration
    source: sensor.1st one (copy paste name)
    name: energy_solar_export
    unit_prefix: k
    round: 2
  - platform: integration
    source: sensor.2nd one (copy paste name)
    name: energy_solar_production
    unit_prefix: k
    round: 2
  - platform: integration
    source: sensor.4th one (copy paste name)
    name: energy_home_consumption
    unit_prefix: k
    round: 2

After that, save the file, in server controls check configuration before restarting. If all looks good reboot and you should have 3 new sensors you created above.

Drop them them into the energy panel config and wait until 12mins past the hour and you should start getting stats.

In the US, AFAIK, we are charged per “therm” (cubic foot) of gas expended not in kWh.

according to wikipedia a therm is equivalent to 100 cubic feet of natural gas.

The therm (symbol, thm) is a non-SI unit of heat energy equal to 100,000 British thermal units (Btu). It is approximately the energy equivalent of burning 100 cubic feet (2.83 cubic metres) – often referred to as 1 CCF – of natural gas.

Since natural gas meters measure volume and not energy content, a therm factor is used by natural gas companies to convert the volume of gas used to its heat equivalent, and thus calculate the actual energy use.