I’ve installed a IR sensor to detect the spin change and prepare a sensor for the consume.
This is the .yaml to read the info:
binary_sensor:
- platform: gpio
id: internal_pulse_counter
pin: GPIO23
internal: true
filters:
- delayed_on: 100ms
on_press:
then:
- lambda: id(total_pulses) += 1;
sensor:
- platform: template
name: "Gas used"
device_class: gas
unit_of_measurement: "m³"
state_class: "total_increasing"
icon: "mdi:fire"
accuracy_decimals: 2
lambda: |-
return id(total_pulses) * 0.01;
This config shows me this info:
[17:20:39][D][sensor:094]: ‘Gas used’: Sending state 23863.52930 m³ with 2 decimals of accuracy
[17:21:39][D][sensor:094]: ‘Gas used’: Sending state 23863.52930 m³ with 2 decimals of accuracy
[17:22:08][D][binary_sensor:036]: ‘internal_pulse_counter’: Sending state OFF
[17:22:08][D][binary_sensor:036]: ‘internal_pulse_counter’: Sending state ON
but the sensor always shows me 23863.52930 m³ but I need the ON/OFF state too. I tried with state_attr(sensor, internal_pulse_counter) but is returning “none”
Has anyone idea to solve it?
Thnks!
EDIT: the binary sensor is not been created in HA but sensor “Gas used” it’s been created