hhaim / hass

home assistant and appdaemon scripts and configuration file
41 stars 16 forks source link

Any description of tasmota_counter sensor? #2

Closed kajmaj closed 5 years ago

kajmaj commented 5 years ago

Hi, your tasmota_sensor looks promising :) Would it be possible to add any description? I've tried to test it, but simple adding of tasmota_counter.py seems to be not the proper way.

hhaim commented 5 years ago

Have a look into Tasmota wiki/home assistant at the end of the page. The code is not sync to latest hass version (88.1) so there is a need for a small fix (see the PR for Tasmota switch) Give me a few days and I will add more info and sync to latest

kajmaj commented 5 years ago

Thanks for info. I will wait for update, it is a good job anyhow

hhaim commented 5 years ago

Checkout README.asciidoc

kajmaj commented 5 years ago

So far I use data ( 100 lt = +1) stored in EEPROM. In my case it is 500 writes per year (50 m3 per year/season going though related watermeter) so wemos should last at least a few years.

I´ve tested your counter (watermeter) and it works well but there are a few issues I guess.

Do you work with those two issuaes somehow?

hhaim commented 5 years ago

Good questions:

There is no need to do anything with Tasmota, the custom component should just work. This is the all point. It saves the absolute reference in HASS database and NOT in the flash (no need to save anything in flash, no need for any rule). So even if you have many power losses and wifi disconnections you won't miss even one pulse.

Make sense?

kajmaj commented 5 years ago

If I understood well, it is all about the math in template.

hhaim commented 5 years ago

No. There are two layers of logic that this simple custom component solves.

  1. Layer one - manage the absolute total pulses (unlimited) from Tasmota and handle the case of power loss/reboot/wifi discounts etc/counter size/mqtt broker faliure etc -- no need for flash write in Tasmota -- this is sore in hass.tasmota_counter.value and it is persistence.
  2. Layer two - convert this absolute number to litter. This is why you need the formula in HASS and not in tasmota. In your case, it's something like this 140*value/4500 litter

In short the custom component will do the job with raw Tasmota, there is no need to do anything from your side (just write once the debounce and TelePeroid) The only thing that can't be done -- is to count pulses while Tasmota has power loss.

Let me know if it works for you?

hhaim commented 5 years ago

One more thing you can do: You can checkout AppDaemon app CWaterMonitor for monitoring the water consumption, notify in cases of irregularity like leakage etc.

kajmaj commented 5 years ago

Under the math I meant "second layer" it is easy to set up in Hass. Counting can be interrupted ( during the measuring cycle) by more reasons:

I am going to test it more thoroughly. Will check CWaterMonitor as well. Thank you

hhaim commented 5 years ago

This is correct. This component solves the issues you mentioned too. This is the nice thing about it - no need for any tricks from Tasmota side. I will close this issue and you could open a new one in case you find an issue.

BTW you could do this check. Go to Tasmota code and change the default value (value after reset) of the counter to be 0xFFFF,FFFF,FFFF,FFFF - 20 and consume a few liters and check hass value

hhaim commented 5 years ago

I’ve looked into Tasmota code. The counter is 32bit and not 64bit. However the conclusions are the same.

kajmaj commented 5 years ago

I am testing it at the moment, it is perfect. Just one question - any possibility to reset your counter sensor?

hhaim commented 5 years ago

Why would you want to do that? The Hass counter should match the counter in the water meter. a workaround would be to change the formula. Another option you can use the "accumulator" custom component that will provide per day/week/month aggregation

kajmaj commented 5 years ago

You are right, if I am thinking back - it would not have any sense.

hhaim commented 5 years ago

I will try to commit it to hass repo (never did that), let's see how it goes

kajmaj commented 5 years ago

Did you succeed with your commitment to the hass repo? Meanwhile, after update to 88.0 there popped up a warning in hassio: Integrations need to be in their own folder. Change sensor/tasmota_counter.py to tasmota_counter/sensor.py. This will stop working soon.

hhaim commented 5 years ago

yes, this is known. This is part of the change I need to do. The model has changed now Sensors/Switch/Binary-sensors are under the domain (tasmota)- I think it is better. So the new component would be

sensor:
    tasmota:
    type: counter
    ..

Will update

hhaim commented 5 years ago

Have a look into the new commit -- there was a small change in counter definition

kajmaj commented 5 years ago

thanks for update. Another question: Accumulator can aggregate different values than on/off time as well? As you said before - daily, weekly consumption, etc?

hhaim commented 5 years ago

It maintained the total time an entity is in a specific state (e.g. the total time a water tap is opened week/day/month) without running a query in the database (slow)

SeByDocKy commented 5 years ago

How to install your tasmota_counter ? For me if I copy the sensor.py into custom_components\tasmota_counter, I got a an error during checking

hhaim commented 5 years ago

Just copy all custom_components and copy the usage from pkgs/water

SeByDocKy commented 5 years ago

Just copy all custom_components and copy the usage from pkgs/water

Thanks I managed to install... now checking is ok but I got this error "the following components and plateforms can not be set up: -tasmota -tasmota.switch

Here is my sensor.yaml input

My tasmota console infos:

08:31:50 MQT: tele/ECS/STATE = {"Time":"2019-05-20T08:31:50","Uptime":"0T00:19:08","Vcc":2.786,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":26,"Wifi":{"AP":1,"SSId":"sebydocky","BSSId":"5C:33:8E:CD:27:FC","Channel":6,"RSSI":46,"LinkCount":1,"Downtime":"0T00:00:09"}} 08:31:50 MQT: tele/ECS/SENSOR = {"Time":"2019-05-20T08:31:50","COUNTER":{"C1":10700},"ENERGY":{"TotalStartTime":"2019-05-19T13:44:19","Total":4.751,"Yesterday":2.811,"Today":1.940,"Period":0,"Power":0,"ApparentPower":0,"ReactivePower":0,"Factor":0.00,"Voltage":0,"Current":0.000}}

Got last HASSIO version 0.93.1

Any tips ?

hhaim commented 5 years ago

it should be under sensor

sensor:

  - platform: tasmota
    name: Eau_chaude_sanitaire
    stopic: ECS
    id: 1
    unit_of_measurement: 'l'
    icon: mdi:water-pump
    expire_after: 300
    value_template: "{{ (45497 + (value))|int }}"
SeByDocKy commented 5 years ago

it should be under sensor

sensor:

  - platform: tasmota
    name: Eau_chaude_sanitaire
    stopic: ECS
    id: 1
    unit_of_measurement: 'l'
    icon: mdi:water-pump
    expire_after: 300
    value_template: "{{ (45497 + (value))|int }}"

Yes but was already in sensor.yaml

and of course in configuration.yaml I got sensor: !include sensor.yaml

hhaim commented 5 years ago

In that case it should work. Provide the full error

SeByDocKy commented 5 years ago

In that case it should work. Provide the full error

Where can I found the full long ? I found nothing in general information of system log

hhaim commented 5 years ago

see here https://community.home-assistant.io/t/var-log-syslog-spammed/10384

hhaim commented 5 years ago

My hass version is 89.1. It might be related. let me sync to latest and recheck

SeByDocKy commented 5 years ago

Tanks a lot. do i need also to install appdeamon too ? for this particular conpound ?

hhaim commented 5 years ago

To use this sensor you just need the custom_component. If you want to leverage the water_app (to find irregularities and notify ) you will need Appdaemon

SeByDocKy commented 5 years ago

No I woud like just:

hhaim commented 5 years ago

AppDaemon is not needed

kajmaj commented 5 years ago

At the moment I am on Home Assistant 0.92.2, tasmota does not work

Log Details (ERROR)
Mon May 20 2019 17:05:57 GMT+0200 (Středoevropský letní čas)
Unable to prepare setup for platform tasmota: Unable to set up component.

Error during setup of component tasmota
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/setup.py", line 153, in _async_setup_component
    hass, processed_config)
  File "/config/custom_components/tasmota/__init__.py", line 84, in async_setup
    for device in cfg.get(CONF_DEVICES):
TypeError: 'NoneType' object is not iterable

Assuming, that error is related to the latest HA changes

SeByDocKy commented 5 years ago

Good, the error is reproductable …. I guess should be an easy fix for you

hhaim commented 5 years ago

fix is here https://github.com/hhaim/hass/commit/44a7b015dc7f7de7810eb7bd2c45828a6348a0aa I never tested it only with counter sensor ..

hhaim commented 5 years ago

BTW it is wasn't related to the hass version (it works with latest) with one sensor now

SeByDocKy commented 5 years ago

fix is here 44a7b01 I never tested it only with counter sensor ..

Thanks :) I will test and report asap I will be home. Actually got one unique water flow sensor…. soon another one will be Added.

hhaim commented 5 years ago

After 6 months with the pulse water meter I would buy a RS485 one instead. There is a need to tune the Debouching value

SeByDocKy commented 5 years ago

RS485

Too many problem with the Tasmota & HASS ?. Actually I also spent some time with the PZEM-004T to monitor my electricity input…. Tasmota serial link can freeze easily. Maybe the pulse counter are already here with ESPhome …. can be a nice alternatve

hhaim commented 5 years ago

There are no issues. Pulse is not that accurate because the pulse can debouching. Tasmota works great. It just an electric property of the pulse. With RS 485(e.g. SDM 630) there is no issue

SeByDocKy commented 5 years ago

Ok now it's working no more error..... Now I have to understand how to tune with my count. I benchmark 400 pulses for 1 liter. How to scale with my own setting ?

I tried:

value_template: "{{ ((value)|float/400.0)| round(2) }}"

it's not the right value....

hhaim commented 5 years ago

Try this value_template: "{{ (0 + (value/400.0))|int }}"

SeByDocKy commented 5 years ago

Should be more or less ok I observed that in the scope

value 1419 old value 20551 uptime sec 750

As you can see the "old value" is the total count.... I don't know if your module reset automatically these counting in tasmota ?

hhaim commented 5 years ago

Looks good. Tasmota counter value is not persistence. This is the objective of this module

SeByDocKy commented 5 years ago

Ok :) .... It's not yet clear in my mind but if it's ok for you. Did you worked a bit how to perform the

hhaim commented 5 years ago

I’m using grafana for that

SeByDocKy commented 5 years ago

ho maybe it's possible to share an example with grafana ? I just installed it ... I am also new with ... sorry to bother you :(

hhaim commented 5 years ago

Sure, will do

hhaim commented 5 years ago

3810D3A9-CBC1-4888-9E68-99140DF7E6C5 EACB342C-2DCC-46CF-A546-A924ABC41381 C9A3B631-E362-4883-B3F1-5856647DFFC5