├── esp32 ├── secrets.yaml ├── wokwi.toml ├── test-esp32-device.yaml └── diagram.json ├── pico-w ├── secrets.yaml ├── wokwi.toml ├── diagram.json └── test-pico-w-device.yaml ├── esp32-local-iot-gateway ├── secrets.yaml ├── wokwi.toml ├── test-esp32-device.yaml └── diagram.json ├── images └── hello_world.png ├── screenshots └── screenshot1.png ├── .gitignore ├── Create-Linux-Python-venv.sh ├── secrets.yaml ├── Create-Windows-Python-venv.ps1 ├── LICENSE ├── .vscode └── tasks.json └── README.md /esp32/secrets.yaml: -------------------------------------------------------------------------------- 1 | <<: !include ../secrets.yaml -------------------------------------------------------------------------------- /pico-w/secrets.yaml: -------------------------------------------------------------------------------- 1 | <<: !include ../secrets.yaml -------------------------------------------------------------------------------- /esp32-local-iot-gateway/secrets.yaml: -------------------------------------------------------------------------------- 1 | <<: !include ../secrets.yaml -------------------------------------------------------------------------------- /images/hello_world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-mentor/ESPHome-Device-Sim/HEAD/images/hello_world.png -------------------------------------------------------------------------------- /screenshots/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-mentor/ESPHome-Device-Sim/HEAD/screenshots/screenshot1.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gitignore settings for ESPHome 2 | # This is an example and may include too much for your use-case. 3 | # You can modify this file to suit your needs. 4 | .esphome 5 | /*/.esphome 6 | /.venv/ 7 | wokwigw.exe 8 | wokwigw -------------------------------------------------------------------------------- /esp32-local-iot-gateway/wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | elf = ".esphome/build/test-esp32-device/.pioenvs/test-esp32-device/firmware.elf" 4 | firmware = ".esphome/build/test-esp32-device/.pioenvs/test-esp32-device/firmware.bin" 5 | 6 | [net] 7 | gateway="ws://localhost:9011" 8 | -------------------------------------------------------------------------------- /Create-Linux-Python-venv.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | python3 -m venv .venv 4 | source .venv/bin/activate 5 | which python 6 | python3 -m pip install --upgrade pip 7 | python3 -m pip --version 8 | python3 -m pip install wheel 9 | python3 -m pip install esphome 10 | python3 -m pip install pillow==10.2.0 11 | python3 -m pip install --upgrade esphome 12 | -------------------------------------------------------------------------------- /secrets.yaml: -------------------------------------------------------------------------------- 1 | #Device Encryption 2 | encryption_key: "eOLRYHE7Bm3A+27kbktjTBjihrHSFBQ5jZ/pOftMyxU=" # test encryption key 3 | 4 | #Wifi Stuff 5 | WiFi_SSID: "Wokwi-GUEST" 6 | 7 | # Web Server Authentication 8 | web_server_username: "admin" 9 | web_server_password: "admin" 10 | 11 | OTA_Password: "OTA_Password" 12 | 13 | AP_Password: "AP_Password" 14 | 15 | -------------------------------------------------------------------------------- /Create-Windows-Python-venv.ps1: -------------------------------------------------------------------------------- 1 | python -m venv .venv 2 | .venv\Scripts\activate 3 | where python 4 | python -m pip install --upgrade pip 5 | python -m pip --version 6 | python -m pip install wheel 7 | python -m pip install esphome 8 | python -m pip install pillow==10.2.0 9 | python -m pip install python-magic-bin==0.4.14 10 | python -m pip install --upgrade esphome -------------------------------------------------------------------------------- /esp32/wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | elf = ".esphome/build/test-esp32-device/.pioenvs/test-esp32-device/firmware.elf" 4 | firmware = ".esphome/build/test-esp32-device/.pioenvs/test-esp32-device/firmware.bin" 5 | 6 | # Forward http://localhost:8180 to port 80 on the simulated ESP32: 7 | [[net.forward]] 8 | from = "localhost:8180" 9 | to = "target:80" 10 | -------------------------------------------------------------------------------- /pico-w/wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | elf = ".esphome/build/test-pico-w-device/.pioenvs/test-pico-w-device/firmware.elf" 4 | firmware = ".esphome/build/test-pico-w-device/.pioenvs/test-pico-w-device/firmware.uf2" 5 | 6 | # Forward http://localhost:8180 to port 80 on the simulated ESP32: 7 | [[net.forward]] 8 | from = "localhost:8180" 9 | to = "target:80" 10 | -------------------------------------------------------------------------------- /pico-w/diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "the-mentor", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { "type": "board-pi-pico-w", "id": "pico", "top": 0, "left": 0, "attrs": {} }, 7 | { 8 | "type": "wokwi-led", 9 | "id": "led1", 10 | "top": -3.6, 11 | "left": -121, 12 | "attrs": { "color": "green" } 13 | } 14 | ], 15 | "connections": [ 16 | [ "pico:GP0", "$serialMonitor:RX", "", [] ], 17 | [ "pico:GP1", "$serialMonitor:TX", "", [] ], 18 | [ "led1:A", "pico:GP5", "green", [ "v0" ] ], 19 | [ "led1:C", "pico:GND.2", "black", [ "v0" ] ] 20 | ], 21 | "dependencies": {} 22 | } 23 | -------------------------------------------------------------------------------- /esp32-local-iot-gateway/test-esp32-device.yaml: -------------------------------------------------------------------------------- 1 | esphome: 2 | name: test-esp32-device 3 | friendly_name: test-esp32-device 4 | 5 | esp32: 6 | board: esp32dev 7 | framework: 8 | type: arduino 9 | 10 | # Enable logging 11 | logger: 12 | 13 | wifi: 14 | ssid: !secret WiFi_SSID 15 | # password: !secret WiFi_Password 16 | 17 | # Enable fallback hotspot (captive portal) in case wifi connection fails 18 | ap: 19 | password: !secret AP_Password 20 | 21 | # Enable Home Assistant API 22 | api: 23 | # encryption: 24 | # key: !secret encryption_key 25 | 26 | ota: 27 | - platform: esphome 28 | # password: !secret OTA_Password 29 | 30 | web_server: 31 | port: 80 32 | auth: 33 | username: !secret web_server_username 34 | password: !secret web_server_password 35 | 36 | captive_portal: 37 | 38 | switch: 39 | - platform: gpio 40 | name: relay 41 | pin: GPIO27 42 | id: relay 43 | restore_mode: restore_default_off 44 | 45 | button: -------------------------------------------------------------------------------- /pico-w/test-pico-w-device.yaml: -------------------------------------------------------------------------------- 1 | esphome: 2 | name: test-pico-w-device 3 | friendly_name: test-pico-w-device 4 | 5 | rp2040: 6 | board: rpipicow 7 | framework: 8 | platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git 9 | 10 | # Enable logging 11 | logger: 12 | 13 | wifi: 14 | ssid: !secret WiFi_SSID 15 | # password: !secret WiFi_Password 16 | 17 | # Enable fallback hotspot (captive portal) in case wifi connection fails 18 | ap: 19 | password: !secret AP_Password 20 | 21 | # Enable Home Assistant API 22 | api: 23 | # encryption: 24 | # key: !secret encryption_key 25 | 26 | ota: 27 | - platform: esphome 28 | # password: !secret OTA_Password 29 | 30 | # web_server: 31 | # port: 80 32 | # auth: 33 | # username: !secret web_server_username 34 | # password: !secret web_server_password 35 | 36 | # captive_portal: 37 | 38 | switch: 39 | - platform: gpio 40 | name: relay 41 | pin: GPIO27 42 | id: relay 43 | restore_mode: restore_default_off 44 | 45 | button: -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Avri Chen-Roth 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /esp32-local-iot-gateway/diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "the-mentor", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { "type": "wokwi-esp32-devkit-v1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, 7 | { "type": "wokwi-resistor", "id": "r1", "top": 90.3, "left": -73.17, "attrs": {} }, 8 | { "type": "wokwi-resistor", "id": "r2", "top": 101.63, "left": -63.17, "attrs": {} }, 9 | { 10 | "type": "wokwi-led", 11 | "id": "led1", 12 | "top": 50.3, 13 | "left": -106.5, 14 | "attrs": { "color": "blue" } 15 | }, 16 | { 17 | "type": "wokwi-led", 18 | "id": "led2", 19 | "top": 68.96, 20 | "left": -127.84, 21 | "attrs": { "color": "green" } 22 | } 23 | ], 24 | "connections": [ 25 | [ "esp:TX0", "$serialMonitor:RX", "", [] ], 26 | [ "esp:RX0", "$serialMonitor:TX", "", [] ], 27 | [ "r1:1", "led1:A", "green", [ "v0.07", "h-10" ] ], 28 | [ "r2:1", "led2:A", "green", [ "v0" ] ], 29 | [ "esp:GND.2", "led2:C", "black", [ "h0" ] ], 30 | [ "esp:GND.2", "led1:C", "black", [ "h0" ] ], 31 | [ "esp:D26", "r1:2", "green", [ "h0" ] ], 32 | [ "r2:2", "esp:D27", "green", [ "v0" ] ] 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "ESPHome Simulator - Run IoT Gateway", 6 | "type": "shell", 7 | "command": "wokwigw --forward 6053:10.13.37.2:6053,2040:10.13.37.2:2040,3232:10.13.37.2:3232,5353:10.13.37.2:5353,8266:10.13.37.2:8266,8892:10.13.37.2:8892,80:10.13.37.2:80,8080:10.13.37.2:80", 8 | "windows": { 9 | "command": "wokwigw --forward 6053:10.13.37.2:6053,2040:10.13.37.2:2040,3232:10.13.37.2:3232,5353:10.13.37.2:5353,8266:10.13.37.2:8266,8892:10.13.37.2:8892,80:10.13.37.2:80,8080:10.13.37.2:80" 10 | }, 11 | "group": "ESPhome-Device-Sim", 12 | "presentation": { 13 | "reveal": "always", 14 | "panel": "new" 15 | } 16 | }, 17 | { 18 | "label": "ESPHome Simulator - Compile Device Firmware", 19 | "type": "shell", 20 | "command": "esphome compile ${input:esphome-yaml-path-param}", 21 | "group": "ESPhome-Device-Sim", 22 | "presentation": { 23 | "reveal": "always" 24 | } 25 | } 26 | ], 27 | "inputs": [ 28 | { 29 | "id": "esphome-yaml-path-param", 30 | "description": "ESPHome Device YAML Path", 31 | "default": "", 32 | "type": "promptString" 33 | }, 34 | ] 35 | } -------------------------------------------------------------------------------- /esp32/test-esp32-device.yaml: -------------------------------------------------------------------------------- 1 | esphome: 2 | name: test-esp32-device 3 | friendly_name: test-esp32-device 4 | 5 | esp32: 6 | board: esp32dev 7 | framework: 8 | type: arduino 9 | 10 | # Enable logging 11 | logger: 12 | 13 | wifi: 14 | ssid: !secret WiFi_SSID 15 | # password: !secret WiFi_Password 16 | 17 | # Enable fallback hotspot (captive portal) in case wifi connection fails 18 | ap: 19 | password: !secret AP_Password 20 | 21 | # Enable Home Assistant API 22 | api: 23 | # encryption: 24 | # key: !secret encryption_key 25 | 26 | ota: 27 | - platform: esphome 28 | # password: !secret OTA_Password 29 | 30 | web_server: 31 | port: 80 32 | auth: 33 | username: !secret web_server_username 34 | password: !secret web_server_password 35 | 36 | captive_portal: 37 | 38 | i2c: 39 | sda: GPIO21 40 | scl: GPIO22 41 | frequency: 400khz 42 | scan: True 43 | 44 | display: 45 | - platform: ssd1306_i2c 46 | model: "SSD1306 128x64" 47 | lambda: |- 48 | it.image(0, 0, id(hello_world), COLOR_OFF, COLOR_ON); 49 | it.line(0, 7, 50, 7); 50 | 51 | image: 52 | - file: "../images/hello_world.png" 53 | id: hello_world 54 | type: grayscale 55 | 56 | switch: 57 | - platform: gpio 58 | name: relay 59 | pin: GPIO27 60 | id: relay 61 | restore_mode: restore_default_off 62 | 63 | button: 64 | -------------------------------------------------------------------------------- /esp32/diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "the-mentor", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { "type": "wokwi-esp32-devkit-v1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, 7 | { "type": "wokwi-resistor", "id": "r1", "top": 90.3, "left": -73.17, "attrs": {} }, 8 | { "type": "wokwi-resistor", "id": "r2", "top": 101.63, "left": -63.17, "attrs": {} }, 9 | { 10 | "type": "wokwi-led", 11 | "id": "led1", 12 | "top": 50.3, 13 | "left": -106.5, 14 | "attrs": { "color": "blue" } 15 | }, 16 | { 17 | "type": "board-ssd1306", 18 | "id": "oled1", 19 | "top": 171.94, 20 | "left": -127.84, 21 | "attrs": { "i2cAddress": "0x3c" } 22 | }, 23 | { 24 | "type": "wokwi-led", 25 | "id": "led2", 26 | "top": 68.96, 27 | "left": -127.84, 28 | "attrs": { "color": "green" } 29 | } 30 | ], 31 | "connections": [ 32 | [ "esp:TX0", "$serialMonitor:RX", "", [] ], 33 | [ "esp:RX0", "$serialMonitor:TX", "", [] ], 34 | [ "r1:1", "led1:A", "green", [ "v0.07", "h-10" ] ], 35 | [ "r2:1", "led2:A", "green", [ "v0" ] ], 36 | [ "esp:GND.2", "led2:C", "black", [ "h0" ] ], 37 | [ "esp:GND.2", "led1:C", "black", [ "h0" ] ], 38 | [ "esp:D26", "r1:2", "green", [ "h0" ] ], 39 | [ "r2:2", "esp:D27", "green", [ "v0" ] ], 40 | [ "esp:GND.2", "oled1:GND", "black", [ "h0" ] ], 41 | [ "esp:VIN", "oled1:VCC", "red", [ "h0" ] ], 42 | [ "esp:D21", "oled1:SDA", "green", [ "h20", "v100", "h0" ] ], 43 | [ "esp:D22", "oled1:SCL", "blue", [ "h30", "v135", "h0" ] ] 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESPHome-Device-Sim 2 | 3 | ## Installation 4 | 5 | To use this ESPHome device simulator you will need the install the following: 6 | 7 | ### VSCode Extensions 8 | * [PlatformIO](https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide) 9 | * [Wokwi Simulator](https://marketplace.visualstudio.com/items?itemName=Wokwi.wokwi-vscode) 10 | 11 | ### Python3 and Python Packages 12 | * `pip3 install wheel` 13 | * `pip3 install esphome` 14 | * `pip3 install pillow==10.2.0` 15 | * On Windows, also: 16 | * `pip3 install python-magic-bin==0.4.14` 17 | 18 | ## How to use the Emulator 19 | * Open a console and navigate to the repo. 20 | * Change directory to the device directory you want to simulate for example `cd esp32` 21 | * Run `esphome compile test-esp32-device.yaml` and wait for the download and compiling to finish. 22 | * In VSCode open the command palette (CTRL+SHIFT+P) and search for `Wokwi: Start Simulator` 23 | * Modify the `test-device.yaml` to test your own code. 24 | 25 | ## Screenshots 26 | ![Example 1](/screenshots/screenshot1.png?raw=true "Example 1") 27 | 28 | ## Customization 29 | You can customize your ESP32 device by adding buttons, sensors, LEDs etc 30 | 31 | 1) Open a new ESP32 project on Wokwi https://wokwi.com/projects/new/esp32 32 | 2) In the simulation side click the "+" and select the parts you want to add. Yes you can add more then one !! 33 | 3) Wire the part to the correct GPIO pins on the ESP32 board. 34 | 4) Go to the `diagram.json` tab and copy the content of the file. 35 | 5) Paste the content into the local `diagram.json` file. 36 | 6) Modify the `test-device.yaml` to work with the new components i've added. 37 | 7) Recompile the ESPHome device by running `esphome compile test-device.yaml`. 38 | 8) Run the Simulator. 39 | 9) PROFIT !! 40 | 41 | ## Thanks 42 | Huge thanks to [Wokwi](https://wokwi.com/) for making this project possible!! --------------------------------------------------------------------------------