laca75tn
(My Home)
May 9, 2022, 3:10pm
1
I want to connect a specific pin to read a value and publish it. The equivalent to:
digitalRead(pin_D5)
sensor:
- platform: gpio
id: 'my_sensor'
pin: D5
on_value:
then:
- !lambda return x;
Do I have to create my own custom sensor to achieve this?
Thanks for your feedback!
zoogara
(Daryl)
May 9, 2022, 9:08pm
2
No.
Digitalread() is just a GPIO Binary Sensor, as you have done. The device_class tells HA how to interpret it - e.g:
binary_sensor:
- platform: gpio
pin: GPIO4
name: "Sunroom PIR"
device_class: motion
It will be published via the api or mqtt depending on your config.
Is it that none of the available device classes match? That’s probably more of a HA issue then.
laca75tn
(My Home)
May 9, 2022, 10:30pm
3
I don’t need to create a binary sensor but a sensor that is going to provide a specific value.
zoogara
(Daryl)
May 9, 2022, 10:35pm
4
What sensor are you trying to read? Both digitalread() and binary_sensor only read whether a pin is high or low.
laca75tn
(My Home)
May 10, 2022, 12:31pm
5
You are correct, I was confused. What I wanted to do is read an analog pin and of course there is a way to do that using the adc sensor. Thanks for pointing me in the right direction.