Just awesome, nothing else to say.
Just start using it!



Yesterday I got my MAX9814 in, last night I got it working.
Used the leds from a lightpainter project to test controlling the leds.
Why is it, that it doesn’t matter how much components and ledstrips you buy, you alway need more.
Arduino Nano, using FastLeds library and FFT.
Ledstrip is WS2812, and the MAX8914 microphone
Example uses a shelly sensor, which has a offset mode in its new firmware. So below is not needed any more.
But the example can be used for any calibration/adjustments.
I’ve put two examples in the NodeRed function
First the solution
var temperature=msg.payload.tC; var humidity=msg.payload.tF; // calc new offset example // simple offset + 2.3 off real measurement msg.payload.tC=temperature + 2.3; // more complex example // take two measurements (with a big difference) msg.payload.tF=1.11 * (humidity - 1); return msg;
First adjustment is plus or minus a value.
Second is more precise when the temperature needs more adjusting
Dots on the red line are measured values
Blue is how it should be
So measured was 2.8 but should be 2
And measured 14.5 but needs to be 15
slope = (14.5-2.8)/(15-2) = 0.9
To get the multiplication factor = 1/0.9 = 1.1111
=(2.8-heightadjust)*1,1111 should give us 2
2/1.1111 = 2.8 – heightadjust
1.8 = 2.8 – heightadjust = 1
So the formula is realhumid = 1,1111 * ( measuredhumid – adjust )
I’ve got a lot of wifi sensors in my home automation.
But also the ones i’ve started with.
The 433mhz temperature,pir and doorsensors.
These are all connected to Domoticz via a rfxcom gateway.
I’ve previously posted about previous setups.
https://www.henriaanstoot.nl/2022/11/03/home-assistant-and-433-dimmers/
https://www.henriaanstoot.nl/2022/11/17/domoticz-nodered-homeassistant-mqtt/
The setup i’ve ended up with is this:
Under hardware in domoticz install the mqtt broker.
Configure your mqtt server (mine is mosquitto)
Add devices to floorplans to send these to Mosquitto
Now i can see the topics in MQTTExplorer
Install the home assistant websocket palette in NodeRed



Configure the nodes like above
These are some example flows (I’ll put the function code below)


Above are the NAMED entities in Home Assistant
CODE
//Code for NR temperature filtering on domoticz IDX
//A door censor uses nvalue instead of svalue1
//Humidity can be svalue2
//Check the Mqtt payload in MQTTExplorer which to use!
var varidx = msg.payload.idx;
var varnvalue = msg.payload.svalue1;
if(varidx == 3108)
{
msg.payload = {};
msg.payload = varnvalue;
return msg;
}
Example of the trigger node.
When a temperature sensor battery dies, and no new data arrives- in 1 hour, I get a pushover warning. (use pushbullet/email/TV notification whatever you want)
Our bedroom has a shelly dimmer, this one is connected with a wall switch and is being controlled by Domoticz, Home Assistant and NodeRed.
I had to fix some stuff, so this was a perfect time to jot down some notes.
I’ve wired it up like this:
(I’ve got a Line wire in my ceiling socket, so i placed the module there instead of the wall socket)
Configure the Shelly as mentioned in the manual. After that do the following:
Advance > Developer settings :
(Enable CoIot if you want a easy auto detect for Home Assistant)
Enable MQTT (This will DISABLE cloud ! )
Server: the ip number of your Mqtt Broker
Next I did was:
Now the wall switch will change/toggle what the current state is.
(If the light is off, and you switch it on using Mqtt, you probably needed to hit the switch two times to turn it off again. Not so with this setting.)
My Nodered Flow ( Not using the Shelly palette nodes in this example)
The Mqtt IN node sets the state of the switch when you use the wall switch!
Cozy turns light on at a specific level.
The slider send an off command when 0% selected, else an on command and the sliders value.
# Cozy function
msg.payload = {};
msg.payload.turn="on";
msg.payload.brightness=30;
return msg;
# Slider function
var varlevel = msg.payload;
msg.payload = {};
if(varlevel == 0){
msg.payload.turn="off";
} else
{
msg.payload.turn="on";
}
msg.payload.brightness=varlevel;
return msg;
DashBoard
The Flow
[
{
"id": "32d1c58277d38408",
"type": "ui_switch",
"z": "746c372deb597681",
"name": "",
"label": "Bedroom lights2",
"tooltip": "",
"group": "c387df0cfc06c60e",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"decouple": "true",
"topic": "",
"topicType": "str",
"style": "",
"onvalue": "on",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "off",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"animate": true,
"className": "",
"x": 220,
"y": 940,
"wires": [
[
"df432d3faea35f38"
]
]
},
{
"id": "fb12eddd50d3013e",
"type": "ui_slider",
"z": "746c372deb597681",
"name": "",
"label": "Bedroom Lights2",
"tooltip": "",
"group": "c387df0cfc06c60e",
"order": 4,
"width": 0,
"height": 0,
"passthru": true,
"outs": "end",
"topic": "",
"topicType": "str",
"min": 0,
"max": "100",
"step": 1,
"className": "",
"x": 230,
"y": 900,
"wires": [
[
"d9c299ec7c0c82b0"
]
]
},
{
"id": "d9c299ec7c0c82b0",
"type": "function",
"z": "746c372deb597681",
"name": "Get level",
"func": "var varlevel = msg.payload;\nmsg.payload = {};\n\nif(varlevel == 0){ \nmsg.payload.turn=\"off\";\n} else\n{\n msg.payload.turn=\"on\";\n}\n\nmsg.payload.brightness=varlevel;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 900,
"wires": [
[
"315ffbe441467c10"
]
]
},
{
"id": "df432d3faea35f38",
"type": "mqtt out",
"z": "746c372deb597681",
"name": "",
"topic": "shellies/shellydimmer-CFE204/light/0/command",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "8c74c5f6.9a7a48",
"x": 800,
"y": 940,
"wires": []
},
{
"id": "315ffbe441467c10",
"type": "mqtt out",
"z": "746c372deb597681",
"name": "",
"topic": "shellies/shellydimmer-CFE204/light/0/set",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "8c74c5f6.9a7a48",
"x": 780,
"y": 900,
"wires": []
},
{
"id": "15f1c904607a0adc",
"type": "function",
"z": "746c372deb597681",
"name": "Cozy",
"func": "msg.payload = {};\n\nmsg.payload.turn=\"on\";\n\nmsg.payload.brightness=30;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 450,
"y": 860,
"wires": [
[
"315ffbe441467c10"
]
]
},
{
"id": "57fb1210d37e5325",
"type": "ui_button",
"z": "746c372deb597681",
"name": "",
"group": "c387df0cfc06c60e",
"order": 5,
"width": 0,
"height": 0,
"passthru": false,
"label": "Bedroom lights2 Cozy",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 240,
"y": 860,
"wires": [
[
"15f1c904607a0adc"
]
]
},
{
"id": "30cba96b08f3b830",
"type": "mqtt in",
"z": "746c372deb597681",
"name": "",
"topic": "shellies/shellydimmer-CFE204/light/0",
"qos": "2",
"datatype": "auto-detect",
"broker": "8c74c5f6.9a7a48",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 240,
"y": 1000,
"wires": [
[
"32d1c58277d38408"
]
]
},
{
"id": "c387df0cfc06c60e",
"type": "ui_group",
"name": "Bedroom",
"tab": "f177532a78f3f1d2",
"order": 3,
"disp": true,
"width": "6",
"collapse": true,
"className": ""
},
{
"id": "8c74c5f6.9a7a48",
"type": "mqtt-broker",
"name": "IPBROKER",
"broker": "IPBROKER",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "15",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "f177532a78f3f1d2",
"type": "ui_tab",
"name": "House",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
See inline comments:
# Add vlan bridge
/interface bridge
add name=bridge_vlan5
# add security profile for wifi
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
add authentication-types=wpa2-psk eap-methods="" mode=dynamic-keys name=iot supplicant-identity=""
# add virtual wifi to 2.4G and 5G APs
/interface wireless
set [ find default-name=wlan2 ] band=2ghz-g/n country=netherlands disabled=no distance=indoors frequency=auto installation=indoor mode=ap-bridge security-profile=xxxxxxxxxxx ssid=MYSSID station-roaming=enabled wireless-protocol=802.11 wps-mode=\
disabled
set [ find default-name=wlan1 ] band=5ghz-a/n/ac channel-width=20/40mhz-Ce country=netherlands disabled=no distance=indoors frequency=auto installation=indoor mode=ap-bridge name=wlan5 security-profile=xxxxxxxxxxxxx skip-dfs-channels=all ssid=\
MYSSID station-roaming=enabled wireless-protocol=802.11 wps-mode=disabled
add disabled=no keepalive-frames=disabled mac-address=4A:8F:5A:48:A4:69 master-interface=wlan2 multicast-buffering=disabled name=wlan_iot2 security-profile=iot ssid=IOT vlan-id=5 vlan-mode=use-tag wds-cost-range=0 wds-default-cost=0 \
wps-mode=disabled
add disabled=no keepalive-frames=disabled mac-address=4A:8F:5A:80:CE:1D master-interface=wlan5 multicast-buffering=disabled name=wlan_iot5 security-profile=iot ssid=IOT vlan-id=5 vlan-mode=use-tag wds-cost-range=0 wds-default-cost=0 \
wps-mode=disabled
# Add vlans to virtual Wifi
/interface vlan
add interface=wlan_iot2 name=vlan5_iot-2 vlan-id=5
add interface=wlan_iot5 name=vlan5_iot-5 vlan-id=5
# add ip range for dhcp
/ip pool
add name=dhcp_pool5_iot ranges=10.5.0.2-10.5.0.200
# add dhcp server with above range
/ip dhcp-server
add address-pool=dhcp_pool5_iot interface=bridge_vlan5 name=dhcpiot
# add vlans and interfaces to vlan bridge
/interface bridge port
add bridge=bridge interface=wlan_iot2
add bridge=bridge interface=wlan_iot5
add bridge=bridge_vlan5 interface=vlan5_iot-5
add bridge=bridge_vlan5 interface=vlan5_iot-2
# add vlan to existing bridge (Not really needed) is for inter vlan traffic
/interface bridge vlan
add bridge=bridge_vlan5 vlan-ids=5
# add interfaces to LAN list (firewall needs this)
/interface list member
add interface=vlan5_iot-2 list=LAN
add interface=bridge_vlan5 list=LAN
add interface=vlan5_iot-5 list=LAN
# Add gateway/dhcpserver ip address
/ip address
add address=10.5.0.254/24 comment="IOT (vlan5)" interface=bridge_vlan5 network=10.5.0.0
# dhcp server network
/ip dhcp-server network
add address=10.5.0.0/24 dns-server=1.1.1.1 gateway=10.5.0.254 netmask=24
# generic NAT rule
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" ipsec-policy=out,none out-interface-list=WAN
A ledstrip on a Harp, now I can see the strings at night!
Woohoo .. ( Little harp in the background (autoharp))
Well .. its a pity that the distance of the leds is NOT the same as the strings distance.
I could light up the string to be played, or even cooler …
When using FFT code (Fast Fourier Transform), I could light up the string being played!
I’m probably going to try to implement this at a later time.
I’ve made a arpscanner in the past
https://www.henriaanstoot.nl/2019/10/15/arpscanner/
But i’m going to migrate the server this is running on.
So I played with ssh commands using ssh connections with a ssh-key, also using Ansible is possible.
ssh user@mikrotik /interface wireless registration-table print
But I didn’t like the continuous logins with automated logins.
So below solution is what i’ve implemented for now.
I’ve installed the IOT extra package from Mikrotik, now I can send MQTT messages from my Wifi enabled Mikrotiks to my Mosquitto broker.
(Download extra package zip, extract iot-7.x-arm.npk, upload this to your mikrotik files folder, and reboot)
The script I’m running on my Mikrotik, sends the active wifi connections with the comments. ( When a comment is set in the Access List, then it’s a know connection )
[admin@RB40111] /iot/mqtt> export # may/15/2023 21:45:12 by RouterOS 7.9 # software id = xxxx-xxxx # # model = RB4011iGS+5HacQ2HnD # serial number = xxxxxxxxxxxxxxxxx /iot mqtt brokers add address=10.1.x.y client-id=rb4011 name=NR
I made the following script on my MT named mqtt
:local broker "NR"
# MQTT topic where the message should be published
:local topic "rb4011/mac"
:foreach i in=[/interface wireless registration-table print proplist=mac-address as-value] do={
:local message "$i"
/iot mqtt publish broker=$broker topic=$topic message=$message
}
A schedule is needed to run this script every 15 minutes
[admin@RB40111] /system/scheduler> export
# may/15/2023 21:48:14 by RouterOS 7.9
# software id = xxxx-xxx
#
# model = RB4011iGS+5HacQ2HnD
# serial number = xxxxxxxxxxx
/system scheduler
add interval=15m name=mqtt on-event=mqtt policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=may/15/2023 start-time=13:30:54
Now all wifi connections will be send to topic rb4011/mac.
# Example .id=*6a;comment=Mobile Henri wlan2;mac-address=44:46:87:xx:xx:xx
Using NodeRed I can make filters and notifications
Below function: get Mac and Comment from payload, if the comment is empty then it is a unknown connection … so send me a warning using Pushover.
// filter function
var output = msg.payload.split(";");
var comment = (output[1].split("="));
var mac = (output[2].split("="));
msg.payload={};
msg.payload = mac[1];
if (comment[1] == "") {
return msg;
}
// is xx:xx:xx:xx:xx:xx online? example
var output = msg.payload.split(";");
var comment = (output[1].split("="));
var mac = (output[2].split("="));
msg.payload={};
msg.payload = mac[1];
if (mac[1] == "xx:xx:xx:xx:xx:xx") {
return msg;
}
Now i’m getting a notification when an unknown wifi connection is made on my Access Point.
( I going to implement the Access List from MT at a later point. No access when not in the Access List)
Follow up on yesterday’s post
Using a html page with javascript, I made a proof of concept displaying realtime information from the sensor.
The sensor is active using a Home Assistant integration.
https://www.henriaanstoot.nl/2022/11/07/home-assistant-nodered-update/
But using the Node-red integration, i take the payload and write this to a mqtt topic
The HTML page below reads the topic using the websocket configured in mosquitto and draws the distance using canvas
cat /etc/mosquitto/conf.d/websockets.conf
listener 9001
protocol websockets
allow_anonymous true
Distance drawn using canvas. Little dividers on top are meters
HTML PAGE with javascript
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript">
var connected_flag=0
var mqtt;
var reconnectTimeout = 2000;
var host="MQTTSERVER";
var port=9001;
var sub_topic="web/#";
function onConnectionLost(){
console.log("connection lost");
document.getElementById("status").innerHTML = "Connection Lost";
document.getElementById("messages").innerHTML ="Connection Lost";
connected_flag=0;
}
function onFailure(message) {
console.log("Failed");
document.getElementById("messages").innerHTML = "Connection Failed- Retrying";
setTimeout(MQTTconnect, reconnectTimeout);
}
function onMessageArrived(r_message){
out_msg="Message received "+r_message.payloadString+"<br>";
//out_msg=out_msg+"Message received Topic "+r_message.destinationName;
//console.log("Message received ",r_message.payloadString);
console.log(out_msg);
document.getElementById("messages").innerHTML =out_msg;
var topic=r_message.destinationName;
if(topic=="web/module1")
{
document.getElementById("module1").innerHTML =r_message.payloadString;
}
if(topic=="web/module2")
{
document.getElementById("module2").innerHTML =r_message.payloadString;
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var centerX = 10;
context.clearRect(0, 0, 1800, 1000);
var centerY = 10;
var radius = r_message.payloadString;
let circle = new Path2D(); //
circle.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
//context.fillStyle = 'white';
context.fillStyle = "rgba(255, 255, 255, 0.2)";
context.fill(circle); //
context.lineWidth = 5;
context.strokeStyle = '#000066';
context.stroke(circle); //
// top line
context.beginPath();
context.moveTo(10, 10);
context.lineTo(1500, 10);
context.stroke();
// 3x dividers
context.beginPath();
context.moveTo(400, 0);
context.lineTo(400, 20);
context.stroke();
context.beginPath();
context.moveTo(800, 0);
context.lineTo(800, 20);
context.stroke();
context.beginPath();
context.moveTo(1200, 0);
context.lineTo(1200, 20);
context.stroke();
}
}
function onConnected(recon,url){
console.log(" in onConnected " +reconn);
}
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
document.getElementById("messages").innerHTML ="Connected to "+host +"on port "+port;
connected_flag=1
document.getElementById("status").innerHTML = "Connected";
console.log("on Connect "+connected_flag);
mqtt.subscribe(sub_topic);
}
function MQTTconnect() {
console.log("connecting to "+ host +" "+ port);
var x=Math.floor(Math.random() * 10000);
var cname="controlform-"+x;
mqtt = new Paho.MQTT.Client(host,port,cname);
//document.write("connecting to "+ host);
var options = {
timeout: 3,
onSuccess: onConnect,
onFailure: onFailure,
};
mqtt.onConnectionLost = onConnectionLost;
mqtt.onMessageArrived = onMessageArrived;
//mqtt.onConnected = onConnected;
mqtt.connect(options);
return false;
}
function sub_topics(){
document.getElementById("messages").innerHTML ="";
if (connected_flag==0){
out_msg="<b>Not Connected so can't subscribe</b>"
console.log(out_msg);
document.getElementById("messages").innerHTML = out_msg;
return false;
}
var stopic= document.forms["subs"]["Stopic"].value;
console.log("Subscribing to topic ="+stopic);
mqtt.subscribe(stopic);
return false;
}
function send_message(msg,topic){
if (connected_flag==0){
out_msg="<b>Not Connected so can't send</b>"
console.log(out_msg);
document.getElementById("messages").innerHTML = out_msg;
return false;
}
var value=msg.value;
console.log("value= "+value);
console.log("topic= "+topic);
message = new Paho.MQTT.Message(value);
message.destinationName = "web/"+topic;
mqtt.send(message);
return false;
}
</script>
</head>
<body onload="MQTTconnect()">
<table>
<tr><td>Sensor1:<td><td id="module1"><td><td >
<tr><td>Sensor2:</td><td id="module2"><td></tr>
</table>
<div id="status">Connection Status: Not Connected</div>
</div>
<br>
Messages:<p id="messages"></p>
<canvas id="canvas" width="1600" height="1000"></canvas>
</body>
</html>
Sometimes you forget you ordered something from Ali Express, it takes too long to arrive.
Today i’ve got this in my mailbox
These are HLK-LD2401B motion/presence detectors € 2,91 a piece.
While PIR sensors are slow and doing only motion sensing, these nice small and cheap devices are fast and have more outputs.
According to the bad translation it can also measure if you ‘devour’ something. Dutch ‘vreten’ means wild fast eating something.
Setting the language to English gives me the word ‘fretting’



Right screenshot shows Coline sitting at a distance of 5.5 meters
Above, the update speed in HA
To try: connect Uart to remote ESP
and tweaking the device
https://www.youtube.com/watch?v=dAzHXpP3FcI
and distance gates
Maybe i can use some Triangulation go find the precise location of a person.