Setup ESP8266 + HCSR501 PIR

Sorry for this topic but im an absolute beginner and i am not sure what exactly to do.

Ive got my

  • ESP8266 board
  • HCSR501 PIR sensor

and i want to use it as presence sensor to be read via MQTT (as documented) via

home/OpenMQTTGateway/HCSR501toMQTT {"presence":"false"}

I do have all the parts and managed to flash the Board wiht a binary for IR-Gateway.

What exaclty do i have to do to get this running?

Is there a completely finished binary to flash or do i have to tell the board that i connected a HCSR501 via some config stuff?

I cant find anything in the documentation, talking especially about using openMQTTGateway in Sensor-Configuration and how to trim it especially for a certain sensor

My guess is, that all of you guys have knowledge about how to deal with these boards and im an absolute newbie

Sorry if i did miss something in the documentation

OK finally made my own build and it seemst that i got it working
Any thoughts on my env-file?

[platformio]
default_envs = nodemcuv2-pilight-pir

[env:nodemcuv2-pilight-pir]
extends = env:nodemcuv2-pilight
lib_deps =
  ${env:nodemcuv2-pilight.lib_deps}
build_flags =
  ${env:nodemcuv2-pilight.build_flags}
  '-DGateway_Name="PIR1"'
  '-DZsensorHCSR501="HCSR501"'
  '-DBase_Topic="OMG/"'
monitor_speed = 115200

Hi @shur3d,

Great that you got it working with your custom environment, but I’m not sure you would need to use the env:nodemcuv2-pilight environment as a basis to extend with your HCSR501, as it doesn’t sound like you’re using any RF/pilight connectivity/functionality with your ESP8266.

So a custom environment with just the basic ESP8266 functionality plus the HCSR501 relevant additoons would be enough.

If and how you want to customise your Base_Topic is really up to you, but you might want to leave it at the default, especially if you possibly will add more OpenMQTTGateways to your setup in the future, and also depending on which controller you are using :wink:

1 Like

Can you tell me what this means?

I have no idea what the basic environment for nodemcuv2 iwithout any specific stuff is

;default_envs = nodemcuv2-all-test
;default_envs = nodemcuv2-fastled-test
;default_envs = nodemcuv2-2g
;default_envs = nodemcuv2-ir
;default_envs = nodemcuv2-rs232

Like this?

Im a bit struggling because i dont know what is minimal needed

[platformio]
default_envs = nodemcuv2-pir

[env:nodemcuv2-pir]
platform = ${com.esp8266_platform}
board = nodemcuv2
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager8266}
  ${libraries.fastled}
build_flags =
  ${com-esp.build_flags}
  '-DGateway_Name="PIR1"'
  '-DZsensorHCSR501="HCSR501"'

No worries, this is already looking very good.

The easiest way to see what is minimally needed for an ESP8266 environment, is to have a look what all/most of the existing nodemcuv2 environments have in common, and what is different depending on their functionality.

[env:nodemcuv2-pir]
platform = ${com.esp8266_platform}
board = nodemcuv2
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager8266}
  ${libraries.esp8266_mdns}
build_flags =
  ${com-esp.build_flags}
  '-DGateway_Name="PIR1"'
  '-DZsensorHCSR501="HCSR501"'

With libraries.fastled not really needed for your project, but libraries.esp8266_mdns making it nicer for accessing on your network, especially if and when you might want to do local OTA updates.

Hope this is running fine for you.

Thank you very much im very impressed on how good my sensor now works

I also added a Temp/Humidity sensor and its a super nice cool and cheap solution

Thank you

my final config:

[platformio]
default_envs = nodemcuv2-pir

[env:nodemcuv2-pir]
platform = ${com.esp8266_platform}
board = nodemcuv2
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager8266}
  ${libraries.esp8266_mdns}
build_flags =
  ${com-esp.build_flags}
  '-DGateway_Name="PIR1"'
  '-DZsensorHCSR501="HCSR501"'
  '-DZsensorHTU21="HTU21"'
1 Like