I turned a simple fog machine into an internet controlled device using ESP8266 and Home Assistant. This project went through at lot of iterations of upgrades and feature addition.

Origin of the idea

The idea of turning a simple fog machine into an internet controlled device originated in an irritation. The fog machine could only be activated manually by pressing a button that was connected with a 0.5 meter cable, which of course is a huge inconvinience during halloween. The owner of the fog machine and I brainstorming, and i remembered i had some ESP8266’s laying around gathering dust. I thought that combining them with Tasmota and Home Asssistant could create a way to “push” the button remotely.

Technical details

Throught this project I’ve used a small variety of electronics and softwares.



  • Tasmota (For the ESP8266)
  • Home Assistant (For the RPI)


Note: Throughout the post i will be refering to Home Assistant as HA


Staring the development of the control box I first started looking into the software side. First task was to make the Tasmotazied ESP and HA able to communicate. Luckily HA has MQTT support which means I can use the already running MQTT on the ESP to beam out and recieve data.

After I succesfully setup the communcation with ease (it took me a while) I made it so that a button in HA would toggle the ESP. I was able to do this because in Tasmota there something called SwitchMode where I just used the Default mode. This meant that when I setup my ESP in HA a toggle switch showed up, so now I could controll the state of a GPIO pin wirelessly in HA.

Now i could succesfully change the state of the relay over the internet!

While I was working on this, the other guy in this project was making the physical control box. The setup of of the control box is as follows:

Setup schematic


After setting this up it was time for testing and…… it worked! We were now able to control the fog machine from the HA app/website. The project was successful, and it worked (almost) flawlessly aside from some wifi connection issues due to lack of range on the ESP, but that was fixed by moving it closer to the AP.


Although the project was completed there were still something missing. The fog machine we had at hand worked like this:

  1. Warm up
  2. Turn on green LED to indicate it’s ready
  3. Be able to spray for about 30 seconds
  4. Return to step 1

This meant that the fog machine had to be in view for us to be able to determine wether it was ready or not. This kind of defeated the purpose of our remote trigger function, because we might as well just press the physical button then. That is when I thought of the analog pin on the ESP. We might be able to use that to trigger some sort of indicator in HA so that we could see in HA when it was ready to spray. I figured out that if we somehow could get a 5V signal from the same source as the green LED, we could make the analog pin act as a sensor in HA. I told my hardware guy that if he could get a 5V signal when the fog machine was ready, I could make a HA sensor that would display it. schematic technical explanation

Now we knew if the fog machine was ready or not without looking at the green LED.


Now we had a way to know if the fog machine was ready to spray or not. Which led to the idea of making an automode feature, which would be an automation in HA that told the ESP to toggle the relay on if the 5V ready signal was on. This made it so that if automode was enabled, the fog machine would:

  1. Warm up
  2. Signal ready
  3. Spray for 30 seconds consecutively
  4. Back to step 1

Although this was technically what we set out to do, we weren’t quite happy with the spraying for 30 seconds then stopping for about 1-2 minutes then spraying again. We discussed if there were any possibilities for us to make it so that you could adjust the spray time. I saw in the Tasmota commands docs that there was a command called PulseTime<x> which could controll how long the relay stayed on after being triggered.

So I set out to make an automation in HA which could make it possible to take an input in HA and publish it in MQTT, which the ESP then picked up and set as it’s PulseTime. I came up with this automation:

Change spray time automation

- id: 'device-id'
  alias: Pulse change
  description: ''
  - platform: state
    - input_text.change_pulse
  condition: []
  - service: mqtt.publish
      topic: cmnd/relay/PulseTime
      payload: '{{ states(''input_text.change_pulse'') }}'
  mode: single

This automation worked like this: If there is a change in the input_text field in HA Then publish the value of input_text on cmd/relay/PulseTime. A smart feature of Tasmota’s MQTT is that if you publish cmd/gpio/command the ESP will execute that as a command, and of course the payload of the “message” is the value of the input_text field.

With this automation it would be possible to control how long the fog machine would spray for each time we toggled it on. This meant that when the device was in automode it would not spray for 30 seconds straight but rather spray for the set amount of time. I then figured out how to change the duration between sensor updates from Tasmota, which meant that if we set it at a fixed value of let’s say 10 seconds then the relay would have a 10 seconds cooldown before it recived a new “turn on” message from HA.

The full automation script of all of this ended up looking like this:

Full HA automation script

- id: 'device-id'
  alias: Listener
  description: ''
  - platform: state
    entity_id: sensor.tasmota_analog_a0
  - if:
    - condition: and
      - condition: numeric_state
        entity_id: sensor.tasmota_analog_a0
        above: 500
      - condition: state
        entity_id: input_boolean.automode
        state: 'on'
    - service: switch.toggle
      data: {}
        device_id: fba9a19ffc4ac5db194358c10928c053
    - service: switch.turn_off
      data: {}
        entity_id: switch.tasmota
  mode: single

This works as follows: If the state of the analog sensor (the 5V signal) changed, then check the value of the sensor (0 is no signal and 1024 is 5V signal) if that value is above 500 and the automode switch is on, then toggle the relay. And if either one of the statements is false then toggle the relay off. This means that if automode is enabled and HA recives an indication that the fog machine is ready, then it will turn the relay on. The relay will then stay on for the set duration and it will automatically turn off again until the wait period is over. But if automode is enabled and the 5V signal is not present (the fog machine is not ready) then nothing will happen. And same case if automode is not enabled.


This was a fun little project, it was in fact my first “complete” project which involved both software but also a surprising amount of hardware. I do apologise for my writing style, but seen as this is my first ever writeup I hope you’ll give me some slack ;)

If this project recives further development then I’ll make a part 2.