Giter Site home page Giter Site logo

timmo001 / esp8266-mqtt-pir-sensor Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 7.0 52 KB

ESP8266 MQTT PIR Sensor. Compatible with Home Assistant's MQTT sensor and binary_sensor

License: Apache License 2.0

C++ 100.00%
nodemcu arduino esp8266 esp8266-arduino mqtt pir-sensor pir sensor sensors passive-infrared-sensor

esp8266-mqtt-pir-sensor's Introduction

ESP8266 MQTT PIR Sensor Build Status

ESP8266 MQTT PIR Sensor. Compatible with Home Assistant's MQTT sensor and binary_sensor

Hardware Example

NodeMCU PIR Sensor

Software Setup

  • Using Atom or VS Code, install Platform IO

  • Once setup, install the esp8266 embedded platform

  • Rename src/setup-template.h to src/setup.h and add your network, MQTT and lighting setup information. Take note of the deviceName you set. You will need this later to subscribe to MQTT messages.

  • Build the project (Ctrl+Alt+B) and check for any errors

    If the build produces an error referencing dependencies, You will need to manually install these libraries:

    • ArduinoJson
    • PubSubClient
  • Upload to your board of choice (Ctrl+Alt+U). This project was created specifically for the NodeMCU but can be configured to work with another WiFi board with some tinkering.

Example Home Assistant Configuration

This example creates a binary_sensor with an automation to brighten a light_group, if another light sensor is below a threshold and a someone is home, then dimming the lights after 10 minutes if the PIR does not detect movement. This will only occur if the lights are still on.

binary_sensor:
  platform: mqtt
  name: Kitchen PIR
  state_topic: sensor/pir001
  payload_on: 1
  payload_off: 0

automation:
  - alias: Kitchen Motion Detected
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_pir
        to: 'on'
    condition:
      - condition: state
        entity_id: group.phones
        state: home
      - condition: numeric_state
        entity_id: sensor.sn1_ldr
        below: '450'
    action:
      - alias: Wake Kitchen lights
        data:
          entity_id: group.kitchen
          brightness_pct: 80
        service: light.turn_on
  
  - alias: 'Reset kitchen lights 10 minutes after last movement'
    trigger:
      platform: state
      entity_id: binary_sensor.kitchen_pir
      to: 'off'
      for:
        minutes: 10
    condition:
      - condition: state
        entity_id: group.phones
        state: home
      - condition: numeric_state
        entity_id: sensor.sn1_ldr
        below: '450'
      - condition: state
        entity_id: light.kitchen_room_lights
        state: 'on'
    action:
      service: homeassistant.turn_on
      entity_id: scene.reset_kitchen_lights

esp8266-mqtt-pir-sensor's People

Contributors

timmo001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.