I had to change the NodeMCU config a bit.
sensor:
- platform: pulse_counter
pin: GPIO12 #D6
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
internal_filter: 29ms
unit_of_measurement: 'Wh'
name: 'Värme'
accuracy_decimals: 0
id: power1
If you import this into Node-red you should be able to see how I solved it. The sensor that the flow outputs is what I used in Home assistant.
[{"id":"7738c465.999994","type":"mqtt in","z":"2ac8cf2d.a326d","name":"Wh String","topic":"power1/sensor/heat/state","qos":"0","datatype":"auto","broker":"a9164020.d4d1d8","x":160,"y":160,"wires":[["1fe5ac5.76003d4"]]},{"id":"1fe5ac5.76003d4","type":"function","z":"2ac8cf2d.a326d","name":"Convert string to integer","func":"msg.payload = Number(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":160,"wires":[["b76c6317.edd5f"]]},{"id":"597e468c.f58","type":"mqtt out","z":"2ac8cf2d.a326d","name":"Wh Accumulated","topic":"sensor/heat/wh/ack","qos":"0","retain":"","broker":"a9164020.d4d1d8","x":1330,"y":160,"wires":[]},{"id":"b76c6317.edd5f","type":"totaliser","z":"2ac8cf2d.a326d","output":"total","interval":"1","intervalUnits":"minutes","name":"Accumulate","x":770,"y":160,"wires":[["76967d1.4acc404"]]},{"id":"76967d1.4acc404","type":"change","z":"2ac8cf2d.a326d","name":"Extract Total","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.total","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":160,"wires":[["597e468c.f58","a3d86d6f.8124b8"]]},{"id":"a3d86d6f.8124b8","type":"debug","z":"2ac8cf2d.a326d","name":"Output Total","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1310,"y":240,"wires":[]},{"id":"a9164020.d4d1d8","type":"mqtt-broker","z":"","name":"Mosquitto","broker":"192.168.0.212","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
And in Home assistant I did this:
sensor:
- platform: mqtt
name: "Värme Wh"
state_topic: "sensor/heat/wh/ack"
varme_kwh:
unit_of_measurement: 'kWh'
value_template: "{{ states('sensor.varme_wh')|float / 1000 }}"
That produced two sensors, one for Wh and one for kWh. I then used the kWh sensor for the energy meter, like this:
utility_meter:
yearly_varme_usage:
source: sensor.varme_kwh
cycle: yearly
tariffs:
- peak
Like I said, not the most elegant solution but it works. Hope it helps!