Is it possible to have ESPHome yaml sensor for a photocell?

I have 2 types/styles of photocells that im trying to use with my NodeMCU 8266. I have a test setup on my arduino and works… , id like to transfer that over to my MCU so i can keep everything nice and small and just report the sensor value back to me so i can act on it.

I have the Sideview 850-980nm Vishay Phototransistor (mouser #782-TEKT5400S)
And i have the Adafruit Photo Cell CDS (485-161)

Stand alone already getting values on my arduino thru the serial monitor , very simple sketch for now.

I want to access that sensors data from ESPHome / HA so i can use it in node red for some automations.

Is it possible? I looked thru all the components, but there is nothing that specifically mentions photo cells /phototransistors…

Is there a generic sensor component that can be used?

Assuming you were just reading the voltage through an analog pin of the arduino, yes.
You can do the same thing on an ESP8266 using the ADC sensor.

At that point, it will give you a sensor of the voltage on that pin. If you want to map that voltage to another value (0-100 for example) you can use the linear calibration filter on the sensor to remap the values. (If you do this, also remember you can manually specify the units it reports as, so it doesnt show volts anymore, by using the unit_of_measurement configuration variable )

So i setup based on the links provided and something shows up now, but dont think its the sensors value.
I say that because the number never changes, light on or off, finger over the sensor, but nothing causes the number to change.

here are the results i see when i upload or change the yaml

[07:42:07][D][adc:056]: 'Office Brightness': Got voltage=0.01V
[07:42:07][D][sensor:092]: 'Office Brightness': Sending state 0.01182 Lux with 1 decimals of accuracy
[07:42:17][D][adc:056]: 'Office Brightness': Got voltage=0.01V
[07:42:17][D][sensor:092]: 'Office Brightness': Sending state 0.01182 Lux with 1 decimals of accuracy
[07:42:27][D][adc:056]: 'Office Brightness': Got voltage=0.01V
[07:42:27][D][sensor:092]: 'Office Brightness': Sending state 0.01182 Lux with 1 decimals of accuracy

And here is the yaml, which im still actively playing around with the calibration filters

sensor:
  - platform: adc
    pin: A0
    name: "Office Brightness"
    update_interval: 10s
    unit_of_measurement: "Lux"
    icon: "mdi:water-percent"
    accuracy_decimals: 1
    filters:
    - calibrate_linear:
        # Map 0.0 (from sensor) to 0.0 (true value)
        - 0.0 -> 0.0
        - 10.0 -> 12.1

The only 3 pins im using on the NODEMCU are the ones circled

Screenshot 2020-10-04 pins

What am i missing? I have even changed it to 5 decimals instead of 1 and still nothing, it just shows the 01182 which never changes…

I played around with the wiring to make sure i had everything right and even tried to edit the sensor information in ESPHOME and nothing, BUT one time i noticed that in the log it did register 1 time, a different reading as seen in the picture and that was without any attempts to cover the sensor or anything else…

I dont understand, if i merely move the breadboard i have over to my arduino setup and watch the serial monitor, the numbers are changing constantly and if i place my finger over the sensor or even cast a shadow over the sensor they change instantly.

I just want to get the same results from the NODEMCU and yaml i have setup.

There has to be something im missing?

What voltage are you getting between GND and Pin A0 using a voltmeter? (using both a bright light and no light)

Seems my multimeter is not working, cant even get reading from a new battery, so will have to go buy a new one later today and test this afternoon.

The only difference between the mcu and arduino, is that on the arduino i have it connected to 5V and on the MCU its on the 3.3v pin

Got a new meter and i get the 3.3 at full light and shadow over the sensor does change the value.

Now what? :man_shrugging:

The specs for the sensor im currently using is the following:
CdS cells are little light sensors. As the squiggly face is exposed to more light, the resistance goes down. When its light, the resistance is about ~1KΩ, when dark it goes up to ~10KΩ.

To use, connect one side of the photo cell (either one, its symmetric) to power (for example 5V) and the other side to your microcontroller’s analog input pin. Then connect a 10K pull-down resistor from that analog pin to ground. The voltage on the pin will be 2.5V or higher when its light out and near ground when its dark.

Then the other sensor (TEKT5400S) i have calls for 5V as well.

I moved my power on the mcu to the VIN pin since i found some posts that it can provide 5v, but after restarting everything, now on HA the value returned is 0.01V

I should be receiving some resistors tonight that i can swap out on the breadboard to make sure i have the right one, but seeing that it works with the arduino setup and the meter does show multiple values are the light changes, seems to be that it is sensing the light around it… :man_shrugging:

Got the new resistors in and rewired the sensor and nodemcu and still nothing :sob:

Any suggestions would be greatly appreciated.

Just noticed something, i moved everything back over to my arduino to test with 3v and see it on the serial monitor, and realized that when i booted back up the NODEMCU in HA the sensor was still recognized and showing the same exact value. Highlighted below that .01v never changed when the sensor was connected to the board and now that its not connected its still there… so not sure what the deal is… i would prefer to use the NodeMCU, but if i cant, i can use my Wemos D1, which is working with the same sensor and reflects instantly on the HA overview… :man_shrugging:

Screenshot 2020-10-06 volts

Since using the NODEMCU was a failure for my sensor, i had been testing with the D1, but that was pretty large, so received my D1 mini’s today and went ahead and setup and soldered everything together to test if it will work.

I have it showing on my dashboard, the sensor registers the light and darkness. So i have secured it to my washer panel and have it over the “Complete” led on the machine and will know if its successful in about 45 minutes when the laundry is complete.

I setup a notification within node red to notify me when the light is bright enough to trigger the notification.

:crossed_fingers:

If this works, then ill need to find a slimmer way to adhere it to the machine so its not a eye sore.
Its a prototype, so right now its wires hot glued to a small plastic sheet that i could secure with tape to the machine and then the hanging off the side of the machine so that i can connect to power

Just wanted to provide a update, if anyone is doing something similar, The sensor worked and notifications worked like a charm, and since our machines dont turn that led off until the lid is opened, we will continue to get the notifications until someone takes out the clothes…

So for now, im calling this setup a success, just need to find a way to make it a smaller foot print so that its not taped over the led.

2 Likes

glad to hear you got it sorted out