hajo62
(Hajo)
January 20, 2021, 4:46pm
1
To avoid a “Die Entität ist nicht-numerisch: sensor.heizung_ventil” message, I was thinkaing about a template, but I still see the not numeric value instead of the gauge. When I test the value_template
it works well.
- platform: mqtt
name: "Heizung Terrasse - Ventil2"
state_topic: "homee/human/Wohnzimmer Heizung Terrasse(2)/CurrentValvePosition(29)"
unit_of_measurement: '%'
icon: mdi:valve
value_template: >
{% if states('sensor.heizung_terrasse_ventil') == 'unknown' %}
{{ '-1' | int }}
{% else %}
{{states('sensor.heizung_terrasse_ventil')}}
{% endif %}
tom_l
January 20, 2021, 4:58pm
2
Did you try:
value_template: >
{% if states('sensor.heizung_terrasse_ventil') == 'unknown' %}
-1
{% else %}
{{states('sensor.heizung_terrasse_ventil')}}
{% endif %}
hajo62
(Hajo)
January 20, 2021, 5:13pm
3
it’s just -1
intead of {{ '-1' | int }}
?
Yes, same result.
m0wlheld
(Christoph Dahlen)
January 20, 2021, 5:26pm
4
{{ -1 if states(...) == 'unknown' else states(...) }}
hajo62
(Hajo)
January 20, 2021, 5:32pm
5
- platform: mqtt
name: "Heizung Terrasse - Ventil2"
state_topic: "homee/human/Wohnzimmer Heizung Terrasse(2)/CurrentValvePosition(29)"
unit_of_measurement: '%'
icon: mdi:valve
value_template: >
{{ -1 if states('sensor.heizung_terrasse_ventil') == 'unknown' else states('sensor.heizung_terrasse_ventil') }}
Same result.
I don’t get it, why do you create an MQTT sensor and then use the state of another sensor to determine the value of the MQTT sensor?
hajo62
(Hajo)
January 20, 2021, 5:36pm
7
The Ventil2 is just to see the original sensor and the sensor after the value_template operation during experimenting with value templates.
Goal is to just have only the corrected sensor, when I got it to work.
But then why is the ventil2 a mqtt sensor and not a template sensor?
What value do you receive on the mqtt topic that shows as unknown?
hajo62
(Hajo)
January 20, 2021, 5:41pm
9
Got that. Removed the original Ventil and changed the new (with template) to Ventil.
name: "Heizung Terrasse - Ventil"
Same result.
Can you please show the config of the original mqtt sensor and tell me what you receive on the topic that makes the value unknown?
1 Like
petro
(Petro)
January 20, 2021, 5:47pm
11
Came here to say this. You don’t need a second sensor, adjust the first to have -1 when it goes unknown.
hajo62
(Hajo)
January 20, 2021, 5:53pm
12
old orignal yaml:
# - platform: mqtt
# name: "Heizung Terrasse - Ventil"
# state_topic: "homee/human/Wohnzimmer Heizung Terrasse(2)/CurrentValvePosition(29)"
# unit_of_measurement: '%'
# value_template: "{{ value_json | round(0) }}"
# icon: mdi:valve
When I just put {{states('sensor.heizung_terrasse_ventil')}}
in the template editor I see unknown
.
Yes, that was my idea but I didn’t get the -1 value…
Remark : That idea is only a work around to get rid of the unknown display after a reboot of HA when using i.e. the gauge card. Any other idea of avoid that ugly display is welcome.
petro
(Petro)
January 20, 2021, 6:01pm
13
Yes, because it references itself and itself doesn’t have information at bootup.
Why do you care if its only momentary?
On reboot, the MQTT server is starting up. Wrapping it in a template sensor is the only option if you don’t want the yellow.
123
(Taras)
January 20, 2021, 6:01pm
14
That’s because the payload published to this topic:
homee/human/Wohnzimmer Heizung Terrasse(2)/CurrentValvePosition(29)
is not published as a retained message.
Do you have any control over the device that publishes to that topic?
hajo62
(Hajo)
January 20, 2021, 6:05pm
15
I’m just restarting HA; and in my docker-compose the mqtt-broker starts before HA.
May you post an example or a link to an example, pls.
Hhm. I’m afraid, not. The sensor comes from homee using the homeetomqtt integration .
And I see the same unknown
with the zigbee2mqtt integration.
123
(Taras)
January 20, 2021, 6:15pm
16
In homeetomqtt’s repository, I see examples for Node-Red. Are you using any Node-Red flows to implement the homeetomqtt integration?
Are you using ZigBee2MQTT’s MQTT Discovery feature or are you defining the entities manually in Home Assistant?
ZigBee2MQTT has a configuration option for retain .
hajo62
(Hajo)
January 20, 2021, 7:16pm
17
No, I just let the values forward to mqtt.
To be honest, I’m not sure. Did this some time ago. Actually I have the sensors defined manually:
- platform: mqtt
name: "XiaomiAqara-1 Temperature"
state_topic: "zigbee2mqtt/XiaomiAqara-1"
unit_of_measurement: '°C'
value_template: "{{ value_json.temperature | round(1) }}"
availability_topic: "zigbee2mqtt/bridge/state"
device_class: "temperature"
What do you suggest? Remove and let the integration re-discover (when the homee2mqtt problem is solved)?
123
(Taras)
January 20, 2021, 8:22pm
18
hajo62:
What do you suggest?
Given that you are not using MQTT Discovery and manually defining the entities, I suggest you enable ZigBee2MQTT’s retain
option.
1 Like
hajo62
(Hajo)
January 20, 2021, 9:03pm
19
123:
not using MQTT Discovery
Got you…
Added retain: true
in the zigbee2mqtt/data/configuration.yaml
and the unknown
is away shortly after the HA restart. Thanks for that hint!
123
(Taras)
January 20, 2021, 9:20pm
20
The same solution would fix the unknown
problem with homeetomqtt, unfortunately it doesn’t offer a way to publish using retain: true
like ZigBee2MQTT does.
I looked at the JavaScript code in one of homeetomqtt’s files called app.js
. That’s the file responsible for publishing payloads. It’s possible to modify the code so that it always publishes payloads as retained messages.
For example, look at line 197 here:
mqttJson.boolData = data.toString().toLowerCase()
if (mqttJson.boolData === '0' || mqttJson.boolData === 'false' || mqttJson.boolData === 'off') {
mqttJson.boolData = 'False'
} else {
mqttJson.boolData = 'True'
}
if (config.publish) {
let publishString = 'homee/' + config.identifier + nodeId.toString() + '/attributes/' + id.toString()
logger.debug(publishString, JSON.stringify(mqttJson, null, 4))
logger.info("publish:", publishString, "JSON")
mqttConnection.publish(publishString, JSON.stringify(mqttJson))
}
if (config.publishHuman) {
let publishString = 'homee/' + config.identifierHuman + nodes[nodeId].name + '(' + nodeId.toString() + ')/' + type.toString() + '(' + id.toString() + ')'
logger.info("publish:", publishString, data)
if (config.filterEchoedMQTTMessages) {
nodes[nodeId].attributes[id].ignoreNextHuman = true
}
mqttConnection.publish(publishString, data.toString())
}
if (config.publishInt) {
I’m no JavaScript expert but I believe all that’s required is to change it to this:
mqttConnection.publish(publishString, JSON.stringify(mqttJson), {retain: true})
1 Like