Correct again. Writing 3k6 instead of 3.6k makes it a lot harder to make mistakes. Especially when schematics were printed in the “olden days”, the decimal point could often go missing.
Ah yes that’s a good point. Thank you
I assume I can connect two FSR’s to the one esp board for bigger bed?
Yeah someone has done that in a post above.
For those who have two FSRs connected to a single ESP board…
I had a single bed occ sensor working great, so I just added a second FSR for the other side of the bed to the same ESP32. BTW, I’m using trim pots, which is a great add for flexibility (use-case = guest room) with thanks to @RoadkillUK
But now I’m stuck at the YAML step. At first I assumed (noob) that I could copy/paste the binary_sensor, sensor, and number sections of the OP’s YAML, change the names and IDs, and then set it to the appropriate pin. But I’m guessing my approach is wrong because I get “Invalid YAML syntax” and “Duplicate key” errors.
I’ve been looking online for documentation on how to add a second device (or would that be entity?) to an existing ESP, but can’t find anything useful. Any pointers? TIA…
Hi Mark, approach sounds right, I’ve done the same thing & it’s working nicely. Change all the names & the pin number. From the error, there might be one more place needs changed. Yes, send YAML.
Here’s my code … Good luck
substitutions:
devicename: bed-sensor
upper_devicename: Bed Sensor
ssid: SSID
esphome:
name: $devicename
on_boot:
priority: 50
then:
- light.turn_off: bedlight
esp32:
board: nodemcu-32s
wifi:
networks:
- ssid: $ssid
password: !secret wifi_password
ap:
ssid: $upper_devicename
password: !secret wifi_password
web_server:
port: 80
logger:
api:
encryption:
key: !secret api_password
ota:
password: !secret ota_password
captive_portal:
light:
- platform: neopixelbus
type: GRB
variant: WS2812
pin: GPIO25
num_leds: 30
name: "Bed Light"
id: bedlight
on_turn_on:
- delay: 5min
- light.turn_off:
id: bedlight
binary_sensor:
- platform: template
name: Right ${upper_devicename}
id: right
device_class: occupancy
lambda: |-
if (id(right_bed_sensor).state > id(right_trigger_level).state) {
return true;
id(right).set_icon("mdi:bed");
} else {
return false;
id(right).set_icon("mdi:bed-empty");
}
- platform: template
name: Left ${upper_devicename}
id: left
device_class: occupancy
lambda: |-
if (id(left_bed_sensor).state > id(left_trigger_level).state) {
return true;
id(left).set_icon("mdi:bed");
} else {
return false;
id(left).set_icon("mdi:bed-empty");
}
- platform: template
name: Single ${upper_devicename}
id: single
device_class: occupancy
lambda: |-
if (id(right).state ||
id(left).state) {
return true;
id(single).set_icon("mdi:bed");
} else {
return false;
id(single).set_icon("mdi:bed-empty");
}
- platform: template
name: Both ${upper_devicename}
id: both
device_class: occupancy
lambda: |-
if (id(right).state &&
id(left).state) {
return true;
id(both).set_icon("mdi:bed");
} else {
return false;
id(both).set_icon("mdi:bed-empty");
}
sensor:
- platform: adc
pin: GPIO34
attenuation: 11db
name: Right ${upper_devicename} Voltage
id: right_bed_sensor
icon: mdi:bed
update_interval: 0.5s
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 1
- or:
- throttle: 180s
- delta: 0.02
- platform: adc
pin: GPIO33
attenuation: 11db
name: Left ${upper_devicename} Voltage
id: left_bed_sensor
icon: mdi:bed
update_interval: 0.5s
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 1
- or:
- throttle: 180s
- delta: 0.02
number:
- platform: template
name: Right Bed Threshold
id: right_trigger_level
optimistic: true
restore_value: True
min_value: 0
max_value: 3.5
step: 0.05
icon: mdi:arrow-collapse-down
unit_of_measurement: V
- platform: template
name: Left Bed Threshold
id: left_trigger_level
optimistic: true
restore_value: True
min_value: 0
max_value: 3.5
step: 0.05
icon: mdi:arrow-collapse-down
unit_of_measurement: V
Nothing there jumps out at me.
Mine’s a little simpler:
esphome:
name: esp1
friendly_name: esp1
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxxxxxxxxxxxxxxxxxx"
ota:
password: "xxxxxxxxxxxxxxxxxxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp1 Fallback Hotspot"
password: "xxxxxxxxx"
captive_portal:
binary_sensor:
- platform: template
name: "Master Bed Left Occupancy"
device_class: occupancy
id: mb_l
lambda: |-
if (id(master_bed_left_sensor).state < id(trigger_level).state) {
return true;
} else {
return false;
}
- platform: template
name: "Master Bed Right Occupancy"
device_class: occupancy
id: mb_r
lambda: |-
if (id(master_bed_right_sensor).state < id(trigger_level).state) {
return true;
} else {
return false;
}
sensor:
- platform: adc
pin: GPIO34
attenuation: 11db
name: "Master Bed Left Sensor"
id: "master_bed_left_sensor"
icon: mdi:bed
update_interval: 0.5s
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 1
- or:
- throttle: 180s
- delta: 0.02
- platform: adc
pin: GPIO35
attenuation: 11db
name: "Master Bed Right Sensor"
id: "master_bed_right_sensor"
icon: mdi:bed
update_interval: 0.5s
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 1
- or:
- throttle: 180s
- delta: 0.02
number:
- platform: template
name: Master Bed Trigger Level
id: trigger_level
optimistic: true
restore_value: true
min_value: 0
max_value: 3.5
step: 0.05
icon: mdi:arrow-collapse-down
unit_of_measurement: V
I just use the Single and Both sensors in conjunction with the alarm so that it will set if one of us is in bed and the other is out. Also I use the Both in bed sensor to run the Daily Reset script.
Thanks guys – I was able to get it to work by paralleling yours as samples. Thank you.
I still got some voltage fluctuations, and after several tests, I noticed that using a multi-USB charger, either from Aliexpress or Amazon, do actually generate these fluctuations:
Has anyone ever encountered this? Is there an electronic or software solution for using a multi-USB charger with an ESP32? Or should I change my multi-USB charger for a better one?
Thanks!
Yes I’ve had issues with noisy USB power supplies before (another ESPHome project). Throw the Ailiexpress one away and get a better one.
Got it. Even this one or this one give me the exact same result. Any relevant multiUSB wall charger brand/model?
Or is there any electronic workaround (resistor/capacitor…) to mitigate this issue?
Thanks!
for some reason, mine isnt working, sensor keeps saying 3.13V
seems to be sending data, just not the correct data, doesnt matter if on or off the bed, just seems to always show 3.13V
i assume something isnt quite right though, just unsure what that would be. its an ESP32
Check your wiring.
I was wondering that, maybe I cooked the resistor.
I have a usb port on my esp board. I can use that to power it yeh? I assumed yes as there’s still 5v and 3v3 at the pins.
Wiring seems fine, same with resistor. I power it with a usb, then soldered an earth out wire to the board. Put one end of the resistor to G34 and the other end to 3v3 along with a wire coming off that same length as my earth and they are what goes to my fsr.
I think I know what I did wrong, I did the power wire out to my fsr on the 3v3 and not the G34, I’ll revise and retest
Ha! Yep that will do it.
Success, 0.7-0.8V in bed, goes to 2.8v ish out.
Thank you!
What kind of terminals/pre made wires do I need so I can just plug and play wires instead of trying to solder them to the dev board pins
Search for “DuPont jumpers”.
Soldering is always more reliable though.