GithubHelp home page GithubHelp logo

bruhautomation / esp-mqtt-json-multisensor Goto Github PK

View Code? Open in Web Editor NEW
340.0 51.0 152.0 1.36 MB

(OBSOLETE) ESP MQTT JSON Multisensor for Home Assistant. Supported sensors include the TEMT6000 light, AM312 PIR, DHT22 temperature/humidity sensors. RGB led supports flash, fade, and transition. Over-The-Air (OTA) uploading, too!

Home Page: https://youtu.be/jpjfVc-9IrQ

License: Apache License 2.0

C++ 100.00%
diy multisensor sensornode homeassistant temperature humidity ota light enclosure photoresistor

esp-mqtt-json-multisensor's Introduction

ESP MQTT JSON Multisensor

This project shows a super easy way to get started with your own DIY Multisensor to use with Home Assistant, a sick, open-source Home Automation platform that can do just about anything.

Bonus, this project requires no soldering and no breadboards - just header wires and the development board!

Video Tutorial - https://youtu.be/jpjfVc-9IrQ

The code covered in this repository utilizies Home Assistant's MQTT JSON Light Component, MQTT Sensor Component, and a NodeMCU ESP8266 development board.

Supported Features Include

  • DHT22 temperature sensor
  • DHT22 humidity sensor
  • AM312 PIR motion sensor
  • photoresistor or TEMT600 light sensor
  • RGB led with support for color, flash, fade, and transition
  • Over-the-Air (OTA) upload from the ArduinoIDE

OTA Uploading

This code also supports remote uploading to the ESP8266 using Arduino's OTA library. To utilize this, you'll need to first upload the sketch using the traditional USB method. However, if you need to update your code after that, your WIFI-connected ESP chip should show up as an option under Tools -> Port -> Porch at your.ip.address.xxx. More information on OTA uploading can be found here. Note: You cannot access the serial monitor over WIFI at this point.

Parts List

Amazon Prime (fast shipping)

Aliexpress (long shipping = cheap prices)

Wiring Diagram

alt text

3D Printed Enclosure

In an effort to make the sensor less ugly, I designed an enclosure in 123D Design and uploaded the STL file in case you want to print your own. It's also availible on Thingiverse. I printed mine on a Prusa I3 clone with a layer height of 0.2 mm, 40% infill, and no supports in ESUN PLA and it turned out great.

Alternatively, you can also make your own enclosure by hand using something like Instamorph. It's themoplastic that melts in hot water and then solidifies to hard plastic at room temperature. You can even get pigment packs and take it next level. I, personally, suck at using it, but it's cheap and functional.

Of course, you can use a project box, tupperware, a card board box, or skip the enclosure all together.

alt text

UPDATED 10 JUN 2017

I added a second version of my enclosure that moves the DHT22 sensor outside the case, removes the standoff for the LDR sensor, and adds a pocket for the LED. This should reduce most of the high temperatures being reported by the board and the removal of the standoff allows you to use either the TEMT600 sensor or photoresistor module. A dab of hot glue can help hold everything in place until you can snap the case together.

A few people have reported that the floating PIR sensor issue is back. If it happens, wrap the PIR module in electrical tape, then aluminum foil, and then electrical tape again. Using the tape will make sure you don't short anything out with the foil on either the module or other components in the system.

Home Assistant Service Examples

Besides using the card in Home Assistant's user interface, you can also use the Services tool to control the light using the light.turn_on and light.turn_off services. This will let you play with the parameters you can call later in automations or scripts.

Fade the Light On Over 5 Seconds - light.turn_on

{"entity_id":"light.sn1_led",
"brightness":150,
"color_name":"blue",
"transition":"5"
}

Flash The Light - light.turn_on

{"entity_id":"light.sn1_led",
"color_name":"green",
"brightness":255,
"flash":"short"
}

Fade the Light Off Over 5 Seconds - light.turn_off

{"entity_id":"light.sn1_led",
"transition":"5"
}

esp-mqtt-json-multisensor's People

Contributors

aaronlayton avatar bruhautomation avatar cbrherms avatar cribbstechnologies avatar jquatier avatar jumpalottahigh avatar vegasiot avatar

Stargazers

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

Watchers

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

esp-mqtt-json-multisensor's Issues

Sensor Data in Serial but not in HA

I can see the data scrolling in the serial connection but HA readings are all UNKNOWN.

topic subscribed in HA (MQTT) is correct

LED control works

UPDATE: Nevermind - it was the MQTT MAX packet size parameter in PubSub Library

LED Flash not using length being set

I have a weird issue where I set the led to flash for 10 seconds, but the mqtt message that is sent has the flash set to 2, no matter the value I set. Have you seen this issue?

*Edit: looks like not even brightness is being ignored too.

action:
    service: light.turn_on
      data:
        entity_id: light.master_led
        color_name: red
        brightness: 100
        flash: 10

Message arrived [(topic)] {"state": "ON", "color": {"r": 255, "g": 0, "b": 0}, "flash": 2, "brightness": 255}

Can't connect to MQTT Server?

Hi, thanks for your efforts on the sensor, very cool.

I get all the way through to flashing the board and looking at the serial port. It connects to my WIFI, but then won't connect to my MQTT server. I think the error is a 'can't establish a TCP connection'. I can ping the nodeMCU and it's live on my network and other devices are interacting with the Mosquitto server normally.

Any ideas?

I'm not using any internal security on the MQTT server, and it's set to allow anonymous connections.

The serial port reports:

calibrating sensor Starting Node named sensornode01

Connecting to ********
.......................................................................................................
WiFi connected
IP address: 
192.168.0.106
Ready
IPess: 192.168.0.106
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds

Temp going up when cooling (have changed to Celsius)

Thanks for a great multisensor-node.

I have a problem with the temp-sensor. When blowing cool air to the sensor it gives higher values (ex. going from 25 Celsius to 35 Celsius). I have tried to switch the 3v and G wires without effect. Im using the DHT22 temp-sensor you have a link to in readme. I have no clue whats wrong.

'D1' was not declared in this scope

I get this error when, Any Idea how to fix this ?


Multisensor:37: error: 'D1' was not declared in this scope

const int redPin = D1;

                ^

Multisensor:38: error: 'D2' was not declared in this scope

const int greenPin = D2;

                  ^

Multisensor:39: error: 'D3' was not declared in this scope

const int bluePin = D3;

                 ^

Multisensor:41: error: 'D7' was not declared in this scope

#define DHTPIN D7

               ^

C:\Users*****\Documents\Arduino\Multisensor\Multisensor.ino:105:9: note: in expansion of macro 'DHTPIN'

DHT dht(DHTPIN, DHTTYPE);

     ^

C:\Users****\Documents\Arduino\Multisensor\Multisensor.ino: In function 'void setup()':

Multisensor:40: error: 'D5' was not declared in this scope

#define PIRPIN D5

               ^

C:\Users*****\Documents\Arduino\Multisensor\Multisensor.ino:114:11: note: in expansion of macro 'PIRPIN'

pinMode(PIRPIN, INPUT);

       ^

Multisensor:41: error: 'D7' was not declared in this scope

#define DHTPIN D7

               ^

C:\Users******\Documents\Arduino\Multisensor\Multisensor.ino:115:11: note: in expansion of macro 'DHTPIN'

pinMode(DHTPIN, INPUT);

       ^

C:\Users*****\Documents\Arduino\Multisensor\Multisensor.ino: In function 'void loop()':

Multisensor:40: error: 'D5' was not declared in this scope

#define PIRPIN D5

               ^

C:\Users*****\Documents\Arduino\Multisensor\Multisensor.ino:397:28: note: in expansion of macro 'PIRPIN'

 pirValue = digitalRead(PIRPIN); //read state of the

                        ^

exit status 1
'D1' was not declared in this scope

LDR all over the place

Hello,

Is there any way to correct this? The sensor i stationary but the values seems to be up/down alot even though the median seems to be correct, looking at the 24h logs.

image

image

MQTT not functional after Wifi disconnect

About once a day my sensor would just stop being able to send or receive data over MQTT. I could still ping the MCU. The serial monitor showed nothing.

I was able to replicate the issue either by simply rebooting my router or using the Wifi MAC filter to temporarily block the MCU. Afterwards the MCU would reconnect to wifi (as evidenced by the ping) but no longer function for MQTT send/receive.

Invalid config for [sensor.mqtt]: value is not allowed for dictionary value @ data[‘device_class’]. Got ‘motion’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.mqtt/

Just upgraded to 0.69.1 (finally as Ubuntu 18.04 is now out and using new python)

but seem to be getting this error and my motion sensors are not showing up.

Invalid config for [sensor.mqtt]: value is not allowed for dictionary value @ data[‘device_class’]. Got ‘motion’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.mqtt/

Problems compiling sketch

Not sure what's happening here. I followed all the directions and I'm just trying to get the main sketch to compile but I'm getting errors with the ESP8266WiFi library.

(I tried putting this in a code block but there's too many single quotes in there for it to get formatted correctly.)

I tried updating to latest Arduino IDE and updating all boards and libraries but still getting the error.

Any idea what could be causing these errors?

C:\Users\Chris\Documents\Arduino\libraries\ESP8266WiFi\src\ESP8266WiFi.cpp: In member function 'void ESP8266WiFiClass::beginSmartConfig()':

C:\Users\Chris\Documents\Arduino\libraries\ESP8266WiFi\src\ESP8266WiFi.cpp:393:76: error: cannot convert 'sc_type' to 'sc_callback_t {aka void ()(sc_status, void)}' for argument '1' to 'bool smartconfig_start(sc_callback_t, ...)'

 smartconfig_start(SC_TYPE_ESPTOUCH, &ESP8266WiFiClass::_smartConfigDone);

                                                                        ^

C:\Users\Chris\Documents\Arduino\libraries\ESP8266WiFi\src\ESP8266WiFi.cpp: In member function 'bool ESP8266WiFiClass::smartConfigDone()':

C:\Users\Chris\Documents\Arduino\libraries\ESP8266WiFi\src\ESP8266WiFi.cpp:409:35: error: 'smartconfig_get_status' was not declared in this scope

 return smartconfig_get_status() == SC_STATUS_LINK_OVER;

                               ^

Multiple libraries were found for "ESP8266mDNS.h"
Used: C:\Users\Chris\Documents\Arduino\libraries\ESP8266mDNS
Not used: C:\Users\Chris\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266mDNS
Multiple libraries were found for "ESP8266WiFi.h"
Used: C:\Users\Chris\Documents\Arduino\libraries\ESP8266WiFi
Not used: C:\Users\Chris\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Contast reboots

I have been using these sensors for the past year and have gone to flash another today and am seeing constant reboots, i tried this on two different chips any idea what the issue may be ?

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld
calibrating sensor Starting Node named sensornode1

Connecting to xxxxxxxxxxxxxxxxxxxxxxxx
.....
WiFi connected
IP address:
192.168.1.105
Ready
IPess: x
Attempting MQTT connection...connected
Setting LEDs:
r: 0, g: 0, b: 0
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"","ldr":"0","temperature":"0.00","heatIndex":"nan"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"standby","ldr":"0","temperature":"0.00","heatIndex":"nan"}
resettin⸮
ets Jan 8 2013,rst cause:2, boot mode:(3,2)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld
calibrating sensor Starting Node named sensornode1

Bruh Multisensor unable to set PIR value and status in Openhab

I am beginner. I am using Openhab2. I can eaxtract Temp, Humidity and LDR, but unable to extract PIR motion status to Openhab2 Basic UI.

My item is as below
String LivingRoom_Motion "Motion Sensor [JSONPATH($.motion):%.1f]" (LivingRoom, gMotion) { mqtt="<[mqttbroker:home/livingroom:state:JSONPATH($.motion)]" }

I am getting "Err" value beside motion in Basic UI.

What should be the item type (I tried Switch, Number and Contact but no success).

Kindly help me in item creation to fetch value.

I am getting following JSON value from sensor

home/livingroom {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"59.60","motion":"standby","ldr":"9","temperature":"31.70","heatIndex":"27.37"}

Kindly help.

Random 0values on HA logging

Build sensor and leave led hardware out. Sensors readings are perfect and seems very accurate.

But randomly couple times of days, every sensor take 0value (temp, humidity, brighness)

Here example picture:
https://i.imgur.com/dSYydNj.png

Try couple different 1.5-2A (5v) power supplyes, not help this situation.

LDR Time Series

Anyone else having this weird time series issue? The lights were off (0 LUX) until 1:27:33PM when I turned them on for a little bit. Instead of the time series being 0 for the time period before I turned on the light there is a diagonal line. Almost like HA isn't logging the 0 data points.

screenshot_20170708-183012

wdt timeout

Is anyone else seeing the WDT timeout issues? For me, the sensor will work for a few days without issue and then it will drop offline. If you look at the console, it will show "wdt timeout ()" and freeze up until its physically unplugged and replugged in. Getting this with a few ESP8266 boards. Anyone have any ideas?

LED brightness

The maximum analogWrite on the ESP8266 value is not 255 (as in the code) but 1023. Because of that the LED is much less bright than it could theoretically be.
Adapting the map-command results in the following problems:

  • larger datatype for the real"Color" variables needed (int would be fitting)
  • the timing concerning fadetimes is different (positive about it: the LED can be dimmed much more smoothly due to more steps)

I tried adapting the code but I failed at the transition-part.
The following piece of code (in the callback-function) should work fine:

realBrightness = map(brightness, 0, 255, 0, 1023);
realRed = int(map(red, 0, 255, 0, realBrightness));
realGreen = int(map(green, 0, 255, 0, realBrightness));
realBlue = int(map(blue, 0, 255, 0, realBrightness));

realBrightness, realRed, realGreen, realBlue must now be integer-variables.

Now theoretically only the problem with the fade time is left: I tried increasing the number of steps from 1020 to 4090 or so... but then I failed making the whole process faster (more steps @ same time -> the Count-Loop must be processed more oftenly -> the whole loop must be faster)...

By the way you also need to adapt the following if-condition:
// Defensive driving: make sure val stays in the range 0-255
if (val > 1023) {
val = 1023;
}

MQTT_MAX_PACKET_SIZE not being recognized

Hi there,

I have build your multisensor and have now spend quite some hours figuring out why my MQTT broker did not receive any JSON messages from it, even though it was successfully authenticated and registered and the ESP could send MQTT test messages.

It seems the parameter MQTT_MAX_PACKET_SIZE does not get applied in my case and no JSON message was sent therefore as they are longer than 128 bytes. For my testing I used your code 1:1, except for the credentials and broker server ip.

The only solution was to change the MQTT_MAX_PACKET_SIZE parameter in the library file "PubSubClient.h" itself.

I see that 8 days ago they made some changes in that area to actually make the size configurable in an INO script, however so far the mentioned "setBufferSize()" method is not available in my library version:
knolleary/pubsubclient@5b23a97

br
Stefan

PIR sensor false trigger and optimal time for delay after PIR detect motion

Hi,
Its is a very awesome DIY product. Although the PIR sensor trigger false alarm, and the detection distance is very small.
I would recommend using a RCWL 9196 / RCWL-0516 radar motion detector module as it had zero interference with nodeMCU module and greater detection distance.

Also it will be very helpful if you can share you experience on the delay time after a motion is detected (default in the code is 100ms, I guess 2 minutes will be a good time before checking and chanigng the state again.

Please suggest.

Error parsing value: 'dict object' has no attribute 'temperature'

Hey guys,
Since reflashing the multisensors with DanielXYZ2000 code revision I've not had any more problems with rubbish 0 values in the HomeAssistant sensor charts. However I do still get these HA internal log errors each time a multisensor either restarts itself, or maybe after a long period with little sensor change (sometimes not for days, then sometimes twice a day, it's very random).
While the 'Error parsing' messages are not stopping anything working, they do distract me from see more crucial info in the logs.
I'd like to eliminate them.

Any of you know why HA still sees a problem with the DHT22 part of the MQTT ?

This is what I get in the logs in a block randomly, alway for the DHT22 related values...
018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'humidity' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.humidity | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'heatIndex' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.heatIndex | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'temperature' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.temperature | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'humidity' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.humidity | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'heatIndex' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.heatIndex | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'temperature' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.temperature | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'humidity' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.humidity | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'heatIndex' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.heatIndex | round(1) }}) 2018-08-10 17:18:17 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'temperature' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.temperature | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'humidity' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.humidity | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'heatIndex' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.heatIndex | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'temperature' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"standby","ldr":"0"}, template: {{ value_json.temperature | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'humidity' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"motion detected","ldr":"0"}, template: {{ value_json.humidity | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'heatIndex' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"motion detected","ldr":"0"}, template: {{ value_json.heatIndex | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'temperature' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"motion detected","ldr":"0"}, template: {{ value_json.temperature | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'humidity' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"motion detected","ldr":"0"}, template: {{ value_json.humidity | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'heatIndex' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"motion detected","ldr":"0"}, template: {{ value_json.heatIndex | round(1) }}) 2018-08-10 17:22:40 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'temperature' (value: {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"motion":"motion detected","ldr":"0"}, template: {{ value_json.temperature | round(1) }})

LED flickering when motion is detected

Hi there,

great piece of code already. I have a small issue that I would like to fix (if possible).
First a little bit about my setup:

I use a single NodeMCU with all of the sensors and an RGB LED attached.
I use a dedicated MQTT server that is connected with the NodeMCU and Home Assistant.
In Home Assistant I have an automation set up that turns on the LED of the NodeMCU using the MQTT method and another automation that turns it off when there is no motion anymore.

At first I had an issue with "flickering states" in Home Assistant that would constantly trigger the "on" and "off" automation even when there was movement at all times.

image

I was able to fix this by introducing a small timeout before setting the pirValue to "standby" or pirState = 2 like this:

int pirValue;
int pirStatus;
int lastTimeMotionDetected = 0;
String motionStatus = "standby";

[...]

pirValue = digitalRead(PIRPIN); //read state of the

if (pirValue == HIGH) {
  lastTimeMotionDetected = millis();
  
  if (pirStatus != 2) {
    motionStatus = "motion_detected";
    sendState();
    pirStatus = 2;
  }
} 
// add a timeout of 5 second before switching to standby to prevent "state flickering" in home assistant when motion is detected
else if (pirValue == LOW && pirStatus != 1 && (millis() > (lastTimeMotionDetected + 5000))) {
  motionStatus = "standby";
  sendState();
  pirStatus = 1;
}

However even though the LED is turned on at all times and Home Assistant doesn't turn it on and off constantly the LED itself flickers in a seemingly random interval of 1-2 seconds while movement is detected. At first I thought this was due to the fact that Home Assistant was switching states but now that Home Assistant doesn't do this anymore I'm kinda out of ideas.

Does someone know why this happens and how to fix this?

Home Assistant is not turning it on and off:
image
(Yes I was actually standing there waving my arms for 2 minutes... xD)

Constant ESP reboots

Hi,

I've just setup 1 of these nodes to test as I want to have motion detection for some of the rooms in my house to control the lights with Home Assistant, however I'm experiencing a constant reboot of the ESP which is a little strange. I've got the ESP connected to my PC via USB to watch the serial monitor for the time being to ensure all messages are getting to MQTT.

Every few minutes (no specific timeout) the ESP is rebooting itself. I've got all the sensors connected except the RGB LED as I'm still waiting for those to arrive and I'm also undecided if I want the LED on all the nodes. The error I'm getting is -

rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

I've had a look and it seems to be related to a reset pin, however I can't really see what's going on. Can anyone help me please?

Thanks!

PIR Oddities!

Great tutorial / project! Having a slight issue with the PIR portion.

I initially wired everything up with a LDR (waiting on a TEMP6000), and an HC-SR501, and couldn't for the life of me get it to work, it was either all motion, or no motion. It was a cheapie and I figured it was the issue you described.

After long wait, my fancy AM312's got here! Same thing.

So I pulled out my analog meter, and saw very very little between Red (VIN) and Black (G) for the PIR sensor. So I move Red (labeled VIN) from it's place by the Black Ground, and up to the 3V by D4. Seems to be fine!

After 2-3 seconds it does show as standby if there's no active motion, but that's functionality to expect from the AM312 as I understand it.

Thoughts? Did I do something silly?

Feature request - Sounder device

Is it possible to add functionality for a buzzer drive from a spare I/O (like D8 perhaps) and control it by MQTT commands. For a door chime beeper from HA or general purpose audible alert from HA ?

Sensor showing 0 values

Hello!

Ordered parts quite some time ago and made everything ready. Yesterday, the board came and i set it up. It's working and showing values, but looking at the history, i get quite a few 0 values. What can cause this? The card is showing information normally, and i dont see these values there (that i have noticed).

The lux sensor has not arrived yet, so this is not reporting - buying figured if this was causing the error, all values would be scrambled?

https://imgur.com/gallery/qCS4SMg

The negative temperature at the start was me forgetting to change to C.

Feature request - BME280 Sensor Support

Wondering how hard it would be to add support for the Bosch BME280 Sensor. Have a few on order, might give it a go myself once I get them. Really just wanted to see if anyone else has already done it or not.

The sensor supports Temp, Hum, and Pressure. All over and I2C connection.

https://www.adafruit.com/product/2652

Well, that and to see if there is any life left on this project. Seems like a lot of people are using it with HA, but this has not been updated in some time.

Not declared buffer size while compiling

Any thoughts would be appreciated why I am receiving this error when compiling the code in Arduino:

Arduino: 1.8.5 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (3M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200"

C:\Users\xxxx\Documents\Arduino\Multisensor_Bruh\sketch_jan01a\sketch_jan01a.ino: In function 'bool processJson(char*)':

sketch_jan01a:260: error: 'StaticJsonBuffer' was not declared in this scope

StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;

^

sketch_jan01a:260: error: 'jsonBuffer' was not declared in this scope

StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;

                             ^

sketch_jan01a:264: error: 'ArduinoJson::JsonObject' has no member named 'success'

if (!root.success()) {

         ^

C:\Users\xxxx\Documents\Arduino\Multisensor_Bruh\sketch_jan01a\sketch_jan01a.ino: In function 'void sendState()':

sketch_jan01a:335: error: 'StaticJsonBuffer' was not declared in this scope

StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;

^

sketch_jan01a:335: error: 'jsonBuffer' was not declared in this scope

StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;

                             ^

sketch_jan01a:340: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson670_0_0::ObjectRef&}' from an rvalue of type 'ArduinoJson670_0_0::ObjectRef'

JsonObject& color = root.createNestedObject("color");

                                                  ^

sketch_jan01a:354: error: 'ArduinoJson::JsonObject' has no member named 'measureLength'

char buffer[root.measureLength() + 1];

                ^

sketch_jan01a:355: error: 'ArduinoJson::JsonObject' has no member named 'printTo'

root.printTo(buffer, sizeof(buffer));

    ^

sketch_jan01a:355: error: 'buffer' was not declared in this scope

root.printTo(buffer, sizeof(buffer));

            ^

exit status 1
'StaticJsonBuffer' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Bad data send when reboot

{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"motion detected","ldr":"0","temperature":"0.00"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"motion detected","ldr":"757","temperature":"0.00"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"motion detected","ldr":"757","temperature":"86.00"}

Multisensor will send "0" when reboot, please help if there is any solution .

Reopen Issue #9

If you don't mind, could you re-open Issue #9 (PIR oddities) - I don't think I can.

Getting very inaccurate temperature readings

Hey guys,

I have six of the sensors around the house, some also where already other sensors exist, so I can compare the results. Something I don't really need another sensor for is the fact, that the remperature is off by some extend. It's always way too high by 5-10°C - same error with °F btw.

Any ideas what could cause this? It makes them practially useless.

Thanks

Temp in C not F?

Hello

This is my 1st project like this and I love it thank you. Since I am English, how do I get it to display the temperature in C not F please?

Cheers
Mark

Add function declarations

I'm not real familiar with this development environment but I've been hacking C code for over 40 years and doing embedded systems for 35+.

I've been using Platformio to program my Sonoff devices so used that to build the Multisensor code as well. I needed to declare all the functions to make it compile (and, really, it's just a "good idea" to do that anyway). Suggest adding them:

void callback(char*, byte*, unsigned int);
void reconnect();
bool processJson(char* message);
void setColor(int inR, int inG, int inB);
int calculateVal(int step, int val, int i);
int calculateStep(int prevValue, int endValue);
void loop();
float calculateHeatIndex(float humidity, float temp);
void software_Reset() ;```

missing define mqtt_port

Hey Ben,

Latest version is missing #define mqtt_port 1883 ;)

Might also be worth adding that a fresh install of the SDK you need to install DHT sensor library and Adfruit unified sensor.

Cheers,
J

Light "blinking"

Problem is i use only one led strip on one "rgb" channel. Because that is normal white strip. I use home assistant white color and only change brightness.

Problem is every time when i put led on that blink (i think full power some period maybe 10-30ms and after that be normal). After about 5-10s do same and continue that forewer. If put light off or pwm 0 then strip be totally shutdown.

Not can use that lighting because that blinks every 5-10secs that 10-30ms full power pulse.

'setup_wifi' was not declared in this scope

I get the following error saying:
exit status 1
'setup_wifi' was not declared in this scope

Arduino: 1.6.7 (Windows 7), Board:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

C:\Users\User\Desktop\ESP-MQTT-JSON-Multisensor-master\ESP-MQTT-JSON-Multisensor-master\bruh_mqtt_multisensor_github\bruh_mqtt_multisensor_github.ino: In function 'void setup()':

bruh_mqtt_multisensor_github:164: error: 'setup_wifi' was not declared in this scope

setup_wifi();

          ^

bruh_mqtt_multisensor_github:167: error: 'callback' was not declared in this scope

client.setCallback(callback);

                  ^

C:\Users\User\Desktop\ESP-MQTT-JSON-Multisensor-master\ESP-MQTT-JSON-Multisensor-master\bruh_mqtt_multisensor_github\bruh_mqtt_multisensor_github.ino: In function 'void callback(char*, byte*, unsigned int)':

bruh_mqtt_multisensor_github:234: error: 'processJson' was not declared in this scope

if (!processJson(message)) {

                       ^

bruh_mqtt_multisensor_github:253: error: 'sendState' was not declared in this scope

sendState();

         ^

C:\Users\User\Desktop\ESP-MQTT-JSON-Multisensor-master\ESP-MQTT-JSON-Multisensor-master\bruh_mqtt_multisensor_github\bruh_mqtt_multisensor_github.ino: In function 'void loop()':

bruh_mqtt_multisensor_github:497: error: 'calculateStep' was not declared in this scope

   stepR = calculateStep(redVal, realRed);

                                        ^

bruh_mqtt_multisensor_github:512: error: 'calculateVal' was not declared in this scope

     redVal = calculateVal(stepR, redVal, loopCount);

                                                   ^

exit status 1
'setup_wifi' was not declared in this scope

temperature and heatIndex values on first boot up

Hello,

Whenever I unplug my sensor or it loses power, the temperature and heatIndex values default to 0 and get sent to my MQTT broker which then makes its way into Home Assistant and results in a spike in the charts.

Here's an example of what it looks like:
image

I tried adjusting the calibrationTime variable but that didn't work. What would be the recommended way to fix this? Is it as simple as using a counter to disregard the first few MQTT values? If it is then maybe I can try and fix it myself, but I thought there might be a better way.

I don't see any MQTT messages in a client.

Hi,
I Like this multisensor a lot! I have one problem. ik don't see the messages in an MQTT client. like MQTT spy. When i subscribe to topic # i don't get any messages. I have owntracks on my phone and that works great in HASSIO mosquitto.

Can anybody help what to look for?

This is the serial monitor in arduino IDE.

...
WiFi connected
IP address: 
192.168.1.13
Ready
IPess: 192.168.1.13
Attempting MQTT connection...connected
Setting LEDs:
r: 0, g: 0, b: 0
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"","ldr":"0","temperature":"0.00","heatIndex":"nan"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"standby","ldr":"0","temperature":"0.00","heatIndex":"nan"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"standby","ldr":"60","temperature":"0.00","heatIndex":"nan"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"0.00","motion":"standby","ldr":"60","temperature":"21.60","heatIndex":"nan"}
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"67.70","motion":"standby","ldr":"60","temperature":"21.60","heatIndex":"16.64"}

Integration with Homeassistant

Hi Ben,
I have configured as per the video. I can see the responses in Serial Monitor of Arduino. I have made changes to configuration file( I am using Hassio). I have installed the mosquito mqtt broker.
{
"plain": true,
"ssl": false,
"anonymous": true,
"logins": [
{
"username": "homeassistant",
"password": "xyz1234"
}
],
"customize": {
"active": false,
"folder": "mosquitto"
},
"certfile": "fullchain.pem",
"keyfile": "privkey.pem"
}
My led turns on for the first time and after 2-3 seconds the switch again toggles automatically and all other sensors are shown as "Unknown". (but in Serial Monitor I can see the responses).
Also when I start the mosquito in hassio as add-in .

starting version 3.2.2
1523878259: mosquitto version 1.4.12 (build date 2017-06-01 13:03:48+0000) starting
1523878259: Config loaded from /etc/mosquitto.conf.
1523878259: Opening ipv4 listen socket on port 1883.
1523878259: Opening ipv6 listen socket on port 1883.
1523878259: Warning: Mosquitto should not be run as root/administrator.
1523878267: New connection from 172.30.32.1 on port 1883.
1523878268: Socket error on client , disconnecting.
1523878268: New connection from 172.30.32.1 on port 1883.
1523878268: New client connected from 172.30.32.1 as fdea50aa-3554-4925-b218-dd7056436b62 (c1, k60, u'homeassistant').
Please suggest ... I hope I am missing something here. I have also done a port forwarding 1883 port of my pi ip.

Also I see we only use here only 1 topic for light , motion and RBG is that correct??
Thanks ,
MJ

Compilation issue on Arduino 1.8.2 on Linux !

Following your great youtube tutorial for setup of the MQTT client with ESP8266 boards !
I have copy/pasted your code from GitHub in Arduino IDE 1.8.2 running on Ubuntu 16.04.2 (I have added all libraries as indicated in your video). I then edited the few lones for Wifi setup, network and MQTT server.
When I try to compile code I have an error:

Arduino : 1.8.2 (Linux), Carte : "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck, Disabled, None"

MQTT-ESP2866:65: error: 'D1' was not declared in this scope
const int redPin = D1;
^
MQTT-ESP2866:66: error: 'D2' was not declared in this scope
const int greenPin = D2;
^
MQTT-ESP2866:67: error: 'D3' was not declared in this scope
const int bluePin = D3;
^
MQTT-ESP2866:69: error: 'D7' was not declared in this scope
#define DHTPIN D7
^
/home/vincen/Bureau/MQTT-ESP2866/MQTT-ESP2866.ino:133:9: note: in expansion of macro 'DHTPIN'
DHT dht(DHTPIN, DHTTYPE);
^
/home/vincen/Bureau/MQTT-ESP2866/MQTT-ESP2866.ino: In function 'void setup()':
MQTT-ESP2866:68: error: 'D5' was not declared in this scope
#define PIRPIN D5
^
/home/vincen/Bureau/MQTT-ESP2866/MQTT-ESP2866.ino:142:11: note: in expansion of macro 'PIRPIN'
pinMode(PIRPIN, INPUT);
^
MQTT-ESP2866:69: error: 'D7' was not declared in this scope
#define DHTPIN D7
^
/home/vincen/Bureau/MQTT-ESP2866/MQTT-ESP2866.ino:143:11: note: in expansion of macro 'DHTPIN'
pinMode(DHTPIN, INPUT);
^
/home/vincen/Bureau/MQTT-ESP2866/MQTT-ESP2866.ino: In function 'void loop()':
MQTT-ESP2866:68: error: 'D5' was not declared in this scope
#define PIRPIN D5
^
/home/vincen/Bureau/MQTT-ESP2866/MQTT-ESP2866.ino:424:28: note: in expansion of macro 'PIRPIN'
pirValue = digitalRead(PIRPIN); //read state of the
^
exit status 1
'D1' was not declared in this scope

Missed something ? I just checked your video but it looks like I have missed none steps :(

Thanks

Vincèn

Compliation issues

Hi anyone able to compile the code with the new versions o the packages ?.

i tries for a whole day and gave up. i kept getting the IRemote..error. I removed the folder but no luck. since i waited @A month had to get the sensor working so i have espeasy on it now and got the 3 sensors working. (not sure how to get the color led configured on esp..so i need to get Ben's code compiled..

I iwll try it again and post the error.
let me know if you are bale to compile with the new pakages ? thanks

No Change in PIR Motion Detected State

I'm running into an issue where there does not seem to be any change from "Motion Detected" back to "standby." Since I'm new to the ESP and PIR, any tips on troubleshooting? I've tried two different PIR modules with no changes, both report motion as soon as the board has booted. The code seems to be working as I get standby if I unplug Vin from the PIR. Could be bad hardware, but I'm unsure. Thanks!

Incorrect Temperature Readings

Hi thanks for the amazing sensor diy.

I have followed everything as per the instructions but my dht22 sensor gives me incorrect temperature readings by 5 to degrees more than the current room temperature. I have changed the dht22 sensor hoping it was faulty but I get the same problem with a new dht22 sensor.

Has anyone come across this issue before?

Any help will be appreciated thanks.

MQTT host not resolving

I can connect to an local MQTT server when I put an IP address but I cannot connect to it via hostname. Yes, the hostname resolves from a desktop and connects.

I know this may not be directly related but does ESP8266 need anything extra to resolve hostnames?

Blue light on sensor startup

I've got 7 BRUH multisensors up and running and I love them and I have 0 problems with them so far!

The only thing that bothers me is that I can't get rid of the blue light. It lights up when I'm connecting it to power but also on, which feels, random times. I could not find anything about this in the code so I was hoping you could push me in the right direction.
I noticed some people in the youtube comments have the same issues.

Thanks and keep up the awesome work!

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.