Skip to content

KBraham/LedDomotics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LedDomotics

Configuration to connect ESP modules to Domotics

Installation

To install LedDomotics the following components are required:

For NodeMCU boards:

For the H801 box:

  • Arduino IDE with ESP8266 support and MQTT library

MQTT

Follow the instructions at http://mosquitto.org/download/

Setting up Node-RED

Execute the following commands to install Node-RED sudo npm install -g node-red node-red

Go to node-red_addr:1883 and start creating the links between all nodes. The following set-up is an example of a working Node-RED architecture for Domoticz to LedDomotics message delivery.

Node-Red architecture

The following function converts the Domoticz output (light level 0-31) to LedDomotics

var position = msg.payload.svalue1;
var level = 0;
if(position === 0){
    
} else if(msg.payload.nvalue === 0) {
    
} else {
  // position will be between 0 and 31
  var minp = 0;
  var maxp = 31;

  // The result should be between 0 and 1023
  var minv = 0;
  var maxv = Math.log(1023);

  // calculate adjustment factor
  var scale = (maxv-minv) / (maxp-minp);

  level = Math.exp(minv + scale*(position-minp));
}

level = Math.floor(level);
return {"payload": {"led":2, "l": level, "ft": 1000}};

In this message led refers to the output pin of the ESP, l is the PWM level ranging from 0 to 1023 and ft is the fadetime, the effective time to use for a transition between levels.

Running NodeMCU

NodeMCU is a platform to run lua scripts on the ESP8266. Make sure to modify the settings in init2 for the correct wifi credentials and mq.lua for the correct MQTT-broker location. To run the scripts simply flash the NodeMCU firmware and upload the three base files to the flash memory.

Each device will identify using its MAC address by default. By looking at the messages send via MQTT (tip: use the websocket interface of mosquitto) you will find a new topic with the correct identifier for each node.

Connecting to Domoticz

The connection between nodes and Domoticz runs via MQTT. To enable this connection activate the MQTT plugin of Domoticz. Doing so makes Domoticz to send all updates via MQTT to the Domoticz/out topic. As Node-RED listens to this topic, it transforms the message to a shorter message processable by the ESP node.

Adding the device to Domoticz

To add the device we need a hardware module in Domoticz. As the communication depends on a virtual device, and we dont use Domoticz drivers, you should create a dummyHW device in Domoticz. For the led dimmer works best using a LightRF type. The autogenerated ID for the device is used to match messages with hardware in Node-RED.

When MQTT is enabled this device should automatically send messages when its status changes, a.k.a. you change the slider.

Updating nodes

To help update nodes in the local network a script upload.py is created. This script takes a local file and uploads it to a remote node. After uploading it automatically restarts the node. This is useful for system upgrades as it allows over-the-air script deployment. Note that the available storage capacity on the ESP chip is very limited. Another common failure is low memory available due to many modules loaded. This can cause the MQTT protocol to fail.

About

Configuration to connect ESP modules to Domotics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published