infra:space-state

Space state

The Space state is the big switch at the entrance of our hackerspace. It allows you to activate the space and make this also known on the internet. The whole mechanism works via three parts. The actual switch, middleware and devices. The switch poses as input mechanism on the actual state of the space. (hence the name space state) The middleware changes some things based on the input. The devices light up or turn on when the space state is active.

The big switch tells our homeassistant that the space is open. The switch connects to a little PCB. The PCB has some LEDs, level shifting and an ESP32 NodeMCU. The NodeMCU runs a script in Micropython. You can find the latest version of the Space state switch in our gitlab archive. Or ask jaand for more information.

The script calls a homeassistant webhook to inform it when state of the switch changes. The new state is passed as payload data to the webhook.

The NodeMCU does a DHCP request using the hostname spacestate.

The LEDs on the board have the following functions:

LED Function
Red Error
Yellow Space state signal (closed is on)
Blue Wifi Connection
Green Power

Homeassistant is setup as middleware. Based on the triggers received via the webhook from the ESP, homeassistant can perform a variety of automations.

Currently it will modify the spaceapi.json setting the value for “open” to either true or false depending on the payload received. It will also submit MQTT messages to all devices to poweron/off.

Currently the following devices should work via the space state status.

  • The neon sign
  • Roboscope
  • Infinity cube
  • Christmass lights
  • Light above the bar
  • Spacemap

These devices are powered via wifi enabled relays that run the Tasmota firmware. Our HomeAssistant service will control the wifi relays.

The devices switch via wifi relays. These relays connect to the regular power and switch via commands given via our 2.4GHz wifi. You can find the relays in the grey 4-way wall sockets. They're in raised wall mounted wall sockets type: ABB HAF 1640. Currently we use 2 different relays: Shelly1 and Sonoff mini. All relays communicate to homeassistant via MQTT. Each device listens on it's own MQTT topic which is autodiscovered by homeassistant.

Tasmota firmware

All the switches shall run on the Tasmota firmware. It is compatible with a lot of devices and has a lot of nice features.

We currently have the following hosts running tasmota:

tasmota_F48871-2161  # Space_Map
tasmota_FBAE8A-3722  # Grote_Bord
tasmota_F40783-1923  # Bar_Licht

You can switch these on and off via Homeassistant/MQTT or directly to the device via HTTP. This is how you do it via HTTP:

#!/bin/bash
for HOST in tasmota_F48871-2161 \
            tasmota_FBAE8A-3722 \
            tasmota_F40783-1923
do echo $HOST
curl $HOST'/cm?cmnd=POWER+ON'
echo "done"
done

If you want to integrate Tasmota switches with Home Assistant you need to do the following 2 actions:

  • Issue “SetOption19 1” in the console
  • Install the tasmota.bin.gz compressed image on the wifi relay if you want to do an OTA upgrade.
  • Make MQTT setting point to our server.

Shelly1

The Shelly1 wifi switch is used for all the devices except the big neon sign. The Shelly1 will break or hang if it switches a fluorescent lamp or neon lamp. (Like the big TD sign). If the Shelly 1 still runs the stock firmware you can find it on the list of devices with a DHCP lease or using mqtt-browser or any other MQTT browser.

The Shelly1 has better stock firmware with a web browser interface and MQTT. The hardware can switch 16 A. But it can't switch the fluorescent lamps (TL-balk) or the big neon sign. Connecting it is also a bit of a hassle.

In order to provide a single software interface for the middleware, the wifi switches should run the tasmota firmware. More information on reprogramming the Shelly1 can be found on: https://tasmota.github.io/docs/devices/Shelly-1/ Information on downloading Tasmota via a wired connection remains here: https://tasmota.github.io/docs/Getting-Started/

Sonoff Mini

For the neon sign we need to use a different wifi relay than the Shelly1. The Shelly1 can't handle the inductive load from the neon sign (or even maybe the roboscope). The Sonoff mini can handle this load (but limited to 10 A) but has horrible firmware. The idea is to update all the smart switches to Tasmota firmware. Then all de devices have the same software interface.

It is possible to update the Sonoff mini to Tasmota via an OTA ugrade. Youneed: Sonoff mini on the local wifi, tasmota binary on webserver on the local subnet and curl. More info here: https://www.sigmdel.ca/michel/ha/sonoff/sonoff_mini_en.html Note: use the tasmota-lite.bin file, the regular file is too large for the Sonoff firmware to flash.

In the case that an original Sonoff Mini is still operational for the space state the following commands can help. Make sure that the device is in DIY mode and connected to our local wifi. Otherwise you need to connect to the Sonoff mini using eWeLink app under Android and then set it to DIY mode.

Find the host:

avahi-browse -t _ewelink._tcp --resolve

This needs the package avahi-deamon and avahi-utils.

You can also search in the syslog of Hitchcock to see which devices with the name ESP_* are currently active.

Get the current status:

curl -d '{"data":{ }}' -X POST http://ESP_FBAE8A:8081/zeroconf/info

Switch on the lamp:

curl -d '{"data":{ "switch":"on"}}' -X POST http://ESP_FBAE8A:8081/zeroconf/switch

Switch off the lamp:

curl -d '{"data":{ "switch":"off"}}' -X POST http://ESP_FBAE8A:8081/zeroconf/switch

You can find more information about controlling the Sonoff Mini via the original firmware here. here





  • infra/space-state.txt
  • Last modified: 17/09/2021 22:10
  • by ron