Difference between revisions of "Spacestate sensors"

From Hackerspace ACKspace
Jump to: navigation, search
m (removed todo)
m (added reference link (calibration))
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{Project
 
{{Project
|State=Stalled
+
|Featured=Yes
 +
|State=Active
 
|Members=Xopr
 
|Members=Xopr
 
|Description=You can't manage what you don't measure
 
|Description=You can't manage what you don't measure
 +
|GitHub=SpaceAPI-sensors
 
}}
 
}}
Note: Onewire sensors are part of the [[ESP8266-SpaceState]] ([[SpaceAPI]]).
+
This project ties strongly with the [[MQTT]] setup (to connect to the [[SpaceAPI]]) as it uses Tasmota<ref name="Tasmota">Tasmota homepage: https://tasmota.github.io/</ref> on [[ESP]] devices for feature bang and ease of use.
Some code is already in place, and using [[ESP8266]] wifi modules make it very modular.
+
 
 +
Note that you're more than welcome to add any sensor (or actuator) that you might see fit for our hackerspace. Think: 3D printer nozzle temperature or filament weight, outside radiation, air quality, motion sensing, window opener and the likes; this project is proof anyone that can handle a screwdriver and PC can do this.
  
 
=== synopsis ===
 
=== synopsis ===
Create a 1-wire network of sensors to keep an eye on temperatures (and/or other stuff), especially for monitoring the server room, and optionally, the [sl|h|st]ackspace(s), probably including the space state switch and the keychain patch rack (sensing keys)..
+
Create a modular repository of sensors and outputs to keep an eye on temperatures (and/or other stuff), especially for monitoring the server room, and optionally, the [sl|h|st]ackspace(s), including the space state switch.
  
 
=== intro ===
 
=== intro ===
After implementing the [[Space state]] switch, a [[Spacestate indicator]] and its [[Mobile Spacestate Indicator|mobile implementation]], it is time to add some extra's to the [[SpaceAPI]], namely: a sensor network.
+
After some iterations of the [[Space state]] switch and [[Mobile Spacestate Indicator|some versions]] of the [[Spacestate indicator]], some different types of temperature sensors, it was time to make it easy on ourselves: switch to [[MQTT]] and use Tasmota<ref name="Tasmota" />.
 +
 
 +
In most cases, an off-the-shelf ESP device will suffice, but since not all devices are not galvanically isolated from mains, it's more practical to use an ESP-12 PCB for things where contacts are bare (like the Space state switch).
 +
 
 +
Here are the steps to setup such a device
  
The idea got triggered due to the fact that sensors are natively supported in the SpaceAPI, and our server room tends to get fairly warm in the summer.
+
=== configuring a spacestate sensor from scratch ===
 +
Most of this (apart from the MQTT configuration) only applies to the Spacestate sensor board (see image); it will setup a pinout template that matches the board.
 +
* Under '''Configuration''', click '''Configure Other'''
 +
* Paste this template: <code>{"NAME":"ACKsensor","GPIO":[0,0,0,0,0,0,0,0,1,0,0,0,1,1],"FLAG":0,"BASE":18}</code> and check '''Activate'''
 +
* Fill in '''Device Name''' (<code>ACKtemp</code> or <code>ACKstate</code>) and '''Friendly Name 1''' (<code>Space state switch</code> or leave as is)
 +
* Save (will reboot)
 +
* Click '''Configure Module'''
 +
* Make sure '''Module type''' is <code>ACKsensor (0)</code>
 +
* Set functions for '''GPIO17 (ADC)''', '''GPIO16''' (Typically <code>Switch 1</code> or <code>Button 1</code>) and '''GPIO12''' (<code>DS18x20</code> which is connected to 3.3v using ~4k7 pull up) <ref>GPIO-Conversion: https://tasmota.github.io/docs/GPIO-Conversion/</ref>
 +
* Save (will reboot again)
 +
* Click '''Configure MQTT'''
 +
* Set '''Host''' (<code>192.168.1.42</code>), User (<code>temperature</code> or <code>spacestate</code>), '''Password''' (currently, only xopr knows these passwords), '''Topic''' (<code>temperature</code>, <code>switch</code> or <code>spacestate</code>) and '''Full Topic''' (<code>ackspace/hackspace/%topic%/%prefix%/</code>)
 +
* Save (will reboot yet again)
  
The plan is to start off with an Arduino + netshield, and later design a small custom PCB with AVR + W5100ENC28J60/WIZ811MJ
+
=== notes and troubleshooting ===
 +
==== GPIO16 ====
 +
Note that this pin is special (it lives on a separate register internally, but more important, its internal pull resistor is to ground (pull-down) <ref>Github comment on GPIO16: https://github.com/arendst/Tasmota/issues/3263#issuecomment-427155769</ref><ref>Usable pins with description: https://tasmota.github.io/docs/Peripherals/#usable-pins</ref><ref>Boot modes and corresponding pin pulling: https://tasmota.github.io/docs/Expanding-Tasmota/#boot-modes</ref>
 +
==== ADC/GPIO17 ====
 +
Note that the analog in is 0-1V maximum; use a voltage divider to limit its input.<ref>Tasmota ADC: https://tasmota.github.io/docs/ADC/</ref> and <ref>calibration/tuning: https://tasmota.github.io/docs/Commands/#adcparam</ref>
  
=== implementation ===
+
==== space state ====
 +
To read a switch without having a corresponding relay one has to remember the default switch action is <code>TOGGLE</code>, which can be used in traveler-system (hotelschakeling) style: one can turn the light on with switch 1, turn it off with switch 2 (software) and turn it on with switch 1 again while the switch physically is in a different state.
 +
To change the behavior of the switch, use <code>switchmode</code><ref>Switchmode: https://tasmota.github.io/docs/Buttons-and-Switches/#switchmode</ref>:
 +
<pre>
 +
switchmode 1
 +
restart 1
 +
</pre>
 +
Note that if you need the reverse (switch connects to poweroff), you need <code>switchmode 1</code>.
 +
Also note that <code>restart 1</code> is needed to store the configuration.
  
Current space RJ45 connector pinput wired to the Raspberry Pi (P-CarPi):
+
==== multiple switches on the spacestate sensor ====
# <strike>Data2</strike>GND
+
By default, one can use a single switch/button without a relay set.
# <strike>GND</strike>Data2
+
If you want to provide MQTT state for multiple switches without having corresponding relay outputs, you need some rule magic;<ref>Distinguish switch 1 and 2 without the use of relay 1 and 2: https://tasmota.github.io/docs/Rules/#distinguish-switch1-and-switch2-without-the-use-of-relay1-and-relay2 this rule section</ref>
# NC
+
<pre>
# VCC
+
Rule1 ON switch1#state DO publish ackspace/hackspace/%topic%/stat/RESULT {"POWER1":"%value%"} ENDON
# NC
+
Rule2 ON switch2#state DO publish ackspace/hackspace/%topic%/stat/RESULT {"POWER2":"%value%"} ENDON
# NC
+
Backlog Rule1 1; Rule2 1
# Data1
+
</pre>
# GND
 
  
On the Raspi, changed the following:
+
==== other devices (switches) ====
in /etc/modules, add w1-gpio and w1-therm on separate lines.
+
Note that the space has a [https://templates.blakadder.com/sonoff_Pow.html modified sonoff POW] (old revision) that allows switching with a regular toggle switch while able to monitor the power usage.
 +
It uses the following template:
 +
<code>{"NAME":"Dangerous POW","GPIO":[32,160,0,0,0,2592,0,0,224,2656,2688,288,0,0],"FLAG":0,"BASE":6}</code>
 +
Note that while the GPIO is 5V relative to GND, it most likely is 225V above earth potential: insulate well and never connect it to your PC.
  
The pins used: 1 (3v3), 7 (Data1), 9 (GND), 11 (Data2)
+
==== calibrating POW module ====
 +
To calibrate a POW module (like in the hackcorner), you need the following<ref>Power Monitoring Calibration: https://tasmota.github.io/docs/Power-Monitoring-Calibration/</ref>:
 +
* Multimeter (for measuring mains voltage)
 +
* Resistive load (higher=better, like the 500W SMD rework station)
  
After the modules have been loaded, you can see the sensors in the /sys/bus/w1/devices/ directory.
+
Steps:
 +
* monitor mains voltage
 +
* go to the sonoff console tab of the device
 +
* turn on the hot air station and crank up the dial
 +
* input the following (adjust the voltage and current accordingly)
 +
: for current, you use the formula: <code>P/U*1000</code> = 500/227*1000 = in this case
 +
<pre>
 +
VoltageSet 227
 +
PowerSet 500
 +
CurrentSet 2202.64
 +
restart 1
 +
</pre>
  
 +
==== recovery ====
 +
When a device doesn't respond or won't connect to wifi, you might need to trigger recovery mode<ref>Device recovery: https://tasmota.github.io/docs/Device-Recovery/</ref> by:
 +
* power it off for 30 seconds
 +
* power on 7 times with less than 10 second interval
 +
Note that this only works if <code>SetOption65</code> is <code>0</code> (which one would have disabled if brown-outs occur often.
  
=== testing ===
+
=== links ===
* I ([[User:Xopr|Xopr]]) modified an RJ45 coupler to have a sensor connected to pins 8, 7 and 4 (Ground, data and Vcc respectively), and while it worked for one night, it became more and more unstable up until the point that it only worked with a 25cm cat5e patchcable.
+
<references/>
* Tested with 25cm 3m and 10m on a 4k7 pull up: worked perfectly!  Next test was with a 25m (not sure actually), and an 85m cable, but using a 1k pullup: worked flawlessly for days!
 
* Tested on Raspi (3v3) with the w1- modules: worked like a charm.
 

Latest revision as of 11:04, 19 June 2022

Project: Spacestate sensors
Featured: Yes
State Active
Members Xopr
GitHub SpaceAPI-sensors
Description You can't manage what you don't measure
Picture
Spacestate sensors Picture.jpg

This project ties strongly with the MQTT setup (to connect to the SpaceAPI) as it uses Tasmota[1] on ESP devices for feature bang and ease of use.

Note that you're more than welcome to add any sensor (or actuator) that you might see fit for our hackerspace. Think: 3D printer nozzle temperature or filament weight, outside radiation, air quality, motion sensing, window opener and the likes; this project is proof anyone that can handle a screwdriver and PC can do this.

synopsis

Create a modular repository of sensors and outputs to keep an eye on temperatures (and/or other stuff), especially for monitoring the server room, and optionally, the [sl|h|st]ackspace(s), including the space state switch.

intro

After some iterations of the Space state switch and some versions of the Spacestate indicator, some different types of temperature sensors, it was time to make it easy on ourselves: switch to MQTT and use Tasmota[1].

In most cases, an off-the-shelf ESP device will suffice, but since not all devices are not galvanically isolated from mains, it's more practical to use an ESP-12 PCB for things where contacts are bare (like the Space state switch).

Here are the steps to setup such a device

configuring a spacestate sensor from scratch

Most of this (apart from the MQTT configuration) only applies to the Spacestate sensor board (see image); it will setup a pinout template that matches the board.

  • Under Configuration, click Configure Other
  • Paste this template: {"NAME":"ACKsensor","GPIO":[0,0,0,0,0,0,0,0,1,0,0,0,1,1],"FLAG":0,"BASE":18} and check Activate
  • Fill in Device Name (ACKtemp or ACKstate) and Friendly Name 1 (Space state switch or leave as is)
  • Save (will reboot)
  • Click Configure Module
  • Make sure Module type is ACKsensor (0)
  • Set functions for GPIO17 (ADC), GPIO16 (Typically Switch 1 or Button 1) and GPIO12 (DS18x20 which is connected to 3.3v using ~4k7 pull up) [2]
  • Save (will reboot again)
  • Click Configure MQTT
  • Set Host (192.168.1.42), User (temperature or spacestate), Password (currently, only xopr knows these passwords), Topic (temperature, switch or spacestate) and Full Topic (ackspace/hackspace/%topic%/%prefix%/)
  • Save (will reboot yet again)

notes and troubleshooting

GPIO16

Note that this pin is special (it lives on a separate register internally, but more important, its internal pull resistor is to ground (pull-down) [3][4][5]

ADC/GPIO17

Note that the analog in is 0-1V maximum; use a voltage divider to limit its input.[6] and [7]

space state

To read a switch without having a corresponding relay one has to remember the default switch action is TOGGLE, which can be used in traveler-system (hotelschakeling) style: one can turn the light on with switch 1, turn it off with switch 2 (software) and turn it on with switch 1 again while the switch physically is in a different state. To change the behavior of the switch, use switchmode[8]:

switchmode 1
restart 1

Note that if you need the reverse (switch connects to poweroff), you need switchmode 1. Also note that restart 1 is needed to store the configuration.

multiple switches on the spacestate sensor

By default, one can use a single switch/button without a relay set. If you want to provide MQTT state for multiple switches without having corresponding relay outputs, you need some rule magic;[9]

Rule1 ON switch1#state DO publish ackspace/hackspace/%topic%/stat/RESULT {"POWER1":"%value%"} ENDON
Rule2 ON switch2#state DO publish ackspace/hackspace/%topic%/stat/RESULT {"POWER2":"%value%"} ENDON
Backlog Rule1 1; Rule2 1

other devices (switches)

Note that the space has a modified sonoff POW (old revision) that allows switching with a regular toggle switch while able to monitor the power usage. It uses the following template: {"NAME":"Dangerous POW","GPIO":[32,160,0,0,0,2592,0,0,224,2656,2688,288,0,0],"FLAG":0,"BASE":6} Note that while the GPIO is 5V relative to GND, it most likely is 225V above earth potential: insulate well and never connect it to your PC.

calibrating POW module

To calibrate a POW module (like in the hackcorner), you need the following[10]:

  • Multimeter (for measuring mains voltage)
  • Resistive load (higher=better, like the 500W SMD rework station)

Steps:

  • monitor mains voltage
  • go to the sonoff console tab of the device
  • turn on the hot air station and crank up the dial
  • input the following (adjust the voltage and current accordingly)
for current, you use the formula: P/U*1000 = 500/227*1000 = in this case
VoltageSet 227
PowerSet 500
CurrentSet 2202.64
restart 1

recovery

When a device doesn't respond or won't connect to wifi, you might need to trigger recovery mode[11] by:

  • power it off for 30 seconds
  • power on 7 times with less than 10 second interval

Note that this only works if SetOption65 is 0 (which one would have disabled if brown-outs occur often.

links