Cheap FOG Machine for Halloween controlled by OpenHAB

Last Halloween I used openHAB to control my Halloween Theme. When Kids came to our door, a motion detector would trigger spooky music, change color of the light outdoors etc. This Halloween I wanted to improve it even further.

I bought a cheap smoke machine on amazon:

Similar to this one:

The only thing I had to do now was to hook the machine up so I could control it with openhab.
I bought a ESP8266 D1 Mini for about 5$, a power regulator and a relay.

The goal was to control the button on the remote by pushing it with the help of the ESP8266 Mini. That way I could control it using openhab

Taking a part the remote control that came with the machine I could measure 12VDC over the button, meaning that if you close the circuit on the remote over the D1 mini you will most likely fry it, since it can’t handle more the 5VDC.

I began by removing the battery and power the remote with a 12VDC adapter. The power regulator can step down the 12VDC to 5VDC, which is fantastic since we then can power the ESP8266 D1 Mini as well. The relay takes a binary output signal and closes the circuit for the 12VDC remote button.

This sketch is somewhat of a joke, but shows somewhat how I have connected everything.

It’s the same principle as this sketch:

I’m controlling it using MQTT, this could be done using REST, but MQTT is really suitable for these kind of things.

The D1 mini wemos code

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

//D1 Mini Button D1 = D3
#define  BUTTON1 D3

WiFiClient   espClient;
PubSubClient mqtt(espClient);
const char* ssid     = "COOLSSID";
const char* password = "supersecret";
const char* host     = "127.0.0.1";

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON1, OUTPUT); //Set output mode on D1
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }
  mqtt.setServer(host, 1883);
  mqtt.setCallback(callback);
}

void reconnect() {
  while (!mqtt.connected()) {
    Serial.print("Attempting to establish MQTT connection.");
    String clientId = "ESP8266Client-SMOKE-";
    clientId += String(random(0xffff), HEX); //Random client Id
    if (mqtt.connect(clientId.c_str())) {
      mqtt.subscribe("iot/smoke1/button1/#"); //Subscripte to all topics for button1
    } else {
      Serial.print("failed, rc=");
      Serial.print(mqtt.state());
      Serial.println(" try again in 5 seconds");
      delay(5000);
    }
  }
  Serial.println("MQTT Connected.");
}

void loop() {
 if (!mqtt.connected()) {
    reconnect();
  }
  mqtt.loop();
}


void callback(char* topic,  byte* payload,  unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  String msg = "";
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
    msg = msg+(char)payload[i];
  }

  if (strcmp(topic, "iot/smoke1/button1/state") == 0 && msg == "ON") {
     pressButton(BUTTON1);
  } else if (strcmp(topic, "iot/smoke1/button1/state") == 0 && msg == "OFF") {
    releaseButton(BUTTON1);
  } else if (strcmp(topic, "iot/smoke1/button1/toggle") == 0 && msg == "2") {
    toggleButton(BUTTON1,2000);
  } else if (strcmp(topic, "iot/smoke1/button1/toggle") == 0 && msg == "4") {
    toggleButton(BUTTON1,4000);
  } else if (strcmp(topic, "iot/smoke1/button1/toggle") == 0 && msg == "6") {
    toggleButton(BUTTON1,6000);
  } else if (strcmp(topic, "iot/smoke1/button1/toggle") == 0 && msg == "8") {
    toggleButton(BUTTON1,8000);
  } else if (strcmp(topic, "iot/smoke1/button1/toggle") == 0 && msg == "10") {
    toggleButton(BUTTON1,10000);
  } 
}

void pressButton(int buttonId) {
  digitalWrite(buttonId, HIGH);
}

void releaseButton(int buttonId) {
  digitalWrite(buttonId, LOW);
}

void toggleButton(int buttonId, int delayTime) {
  digitalWrite(buttonId, HIGH); 
  delay(delayTime);
  digitalWrite(buttonId, LOW);
}

This gives us the ability to push the button using the following topics and messages:

  • iot/smoke1/button1/state (ON/OFF) On will push button down, OFF will release button
  • iot/smoke1/button1/toggle (10,8,6,4,2) Toggle the button with 10-2 seconds delay inbtween

In openhab I created a mqtt Thing:
It is of course possible and even recommended to add the Thing in Paperui.

Bridge mqtt:broker:mycoolmqtt [ host="127.0.0.1", secure=false ]
{
    Thing topic smoke1 "Smoke Machine" {
    Channels:
        Type switch : state "SmokeMachine Switch" [ commandTopic="iot/smoke1/button1/state", on="ON", off="OFF"]
        Type switch : t10s "Toggle 10 Seconds" [ commandTopic="iot/smoke1/button1/toggle", on="10"] 
        Type switch : t8s "Toggle 8 Seconds" [ commandTopic="iot/smoke1/button1/toggle", on="8"] 
        Type switch : t6s "Toggle 6 Seconds" [ commandTopic="iot/smoke1/button1/toggle", on="6"]
        Type switch : t4s "Toggle 4 Seconds" [ commandTopic="iot/smoke1/button1/toggle", on="4"] 
        Type switch : t2s "Toggle 2 Seconds" [ commandTopic="iot/smoke1/button1/toggle", on="2"]     
    }
}

Items:

Switch HalloweenSmoke               "Halloween Smoke [%s]"            { channel="mqtt:topic:mycoolmqtt:smoke1:state" } 
Switch HalloweenSmokeTogge10s        "Halloween toggle 10s [%s]"       { channel="mqtt:topic:mycoolmqtt:smoke1:t10s", expire="10s" } 

I can now control my Smoke Machine using OpenHAB. The controller is power with a 230V AC to 12VDC adapter for $5. I’ve also put the components in a IP65 housing.

/S

5 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.