Not sure what to tell you. The template is correct in regards to what has been shown from you. Did you try 123s?
If think it should be
availability_template: "{{ 'online' if (value.split(',')[1] | is_number) else 'offline' }}
Per the doc of āavailability_templateā
This.
I missed that important detail; the default values for reporting availability/unavailability arenāt true
/false
but online
/offline
.
Use either the corrected template posted by koying:
availability_template: "{{ 'online' if value.split(',')[1] | is_number else 'offline' }}"
or this one I suggested earlier:
availability_template: "{{ 'online' if value.split(',')[1] | int(-1) > 0 or 'offline' }}"
The only difference between the two is that the second one will also reject negative values. So if a negative value is received it will make the sensor unavailable
and the negative value will not be reported. If you want it to report any negative values received, use koyingās version.
thanks to all for the support.
with this code:
- platform: mqtt
name: mqttenergy
state_topic: home-assistant/sensor03/messaggio
value_template: "{{ value.split(',')[1] }}"
availability_topic: home-assistant/sensor03/messaggio
availability_template: "{{ 'online' if value.split(',')[1] | int(-1) > 0 or 'offline' }}"
device_class: energy
state_class: total_increasing
unit_of_measurement: "kWh"
the sensor works, but the peaks in energy module remainsā¦
a strange thing:
when I reboot the sensor shows for few seconds this value:
and after the correct value:
I see this value also there:
ā¦maybe i found the problem:
there was only one value retained. so at each reboot, HA sees the āretained wrong valueā 4932783.
so the peak is the result of 6060304-4932783ā¦
I supposeā¦
I donāt know why you refer to it as a āwrongā value because, based on the last screenshot in your post, itās clear that the energy module is actually publishing it. In other words, itās not due to any fault of Home Assistant misrepresenting the information; itās what is actually being received.
You should be investigating the energy module to determine why it behaves the way it does.
TBH the value in general looks off to me. Houses average 893 kWh per month and enry86cami is sitting at 5 million kwh. In general, I think the sensor is being miss understood and used.
Itās an aluminum smelter.
Cheese and rice, how many tons is this thing makingā¦ 300 tons?
I suppose you could filter out any value greater than a given threshold. For example, this will report the sensor is available
only if the value is between zero and ten thousand (adjust it to suit your needs).
availability_template: "{{ 'online' if 0 < value.split(',')[1] | int(-1) < 10000 or 'offline' }}"
with the software MQTT.fx, after connected to the MQTT broker I always had this first value retained:
but is an old value.
with the software MQTT EXPLORER I removed this value and now I donāt have a value retained.
with MQTT EXPLORER I found other old sensor with retained values. these are old sensor actually disconnected to the LAN. So I performed a clean of the āOLD MQTT PACKAGEā in my lan.
In fact now, by MQTT.fx I donāt see anymore a retained value:
But I donāt know how could be happened that some value had retainedā¦
So I suppose that my problem was this old value āin pendingā into the lanā¦
In your latest screenshot, itās reporting over 6 million kWh. Is that correct?
If it is correct, what is this sensor monitoring?
Yes, it is correct but the unit of measurement is Wh, so it is 6.000kWh. About one year of my home electric consumption.
The unit_of_measurement
you specified in the sensorās configuration is kWh
. I suggest you modify the sensorās value_template so it converts the received value, in Wh, to a reported value in kWh.
value_template: "{{ (value.split(',')[1] | int(0)) / 1000 }}"
youāre right, my conf works only because the HA energy module works with differences
Hi
Having the same problem but with awatewr comsuption. I have a sensor taht starts with 0 when I restart the HA and seconds later recover last values.
- platform: template
sensors:
diario_agua_disponible:
friendly_name: ādiario agua availableā
entity_id: sensor.diario_agua_con_acumulado_estimado_duplicated
value_template: ā{{ (states(āsensor.diario_agua_con_acumulado_estimado_duplicatedā) | float ) | round(2) }}ā
availability_template: ā{{ not is_state(āsensor.diario_agua_con_acumulado_estimado_duplicatedā, āunknownā,ā0.0ā, ā0,0ā ) }}ā
I can observe taht sensor starts as a Unknown for a seconds , after that change to 0.0 and after that to the correcta value.
Impossible to keep it unavailable till have the correct value.
Any recomendation?