Im working with esp8266 and Im creating my own firmware for my home devices. Working on it I found a "problem" (the egg or the chicken).
Case: If you create a sensor (like light/switch) you can create it manually on domoticz and after that the sensor can be updated sending a mqtt message but you need to know the idx
Code: Select all
... {"idx" : 7, "nvalue" : 0, "svalue" : "0"} -t 'domoticz/in'
From here all its ok, but the problem comes when you deplpy a new instance of domocitz, you dont have any idx created and you have old "sensor" with old idx. Obiously you can not create a "custom idx", for this reson I have been migrating to "auto-discovery"
Why? because in real life the first time that I connect a device (phisical device) I dont know what idx correspond.
of course... I created manually the device and after that, put that idx on my new physical device, but Im trying to create a little more "professional" procedure.
To test the "AD" I send MQTT messages "auto-discovery-message" and create virtual thing with my unique ID (not idx, this idx will be created automatically by domoticz).
Code: Select all
mosquitto_pub -u admin -P admin -h 127.0.0.1 -p 1883 \
-m '{"name": "ligth99", "command_topic": "999/set", "state_topic": "999/state", "unique_id": "999", "payload_on": "ON", "payload_off": "OFF", "retain": true }' -t 'homeassistant/binary_sensor/999/config'
Code: Select all
mosquitto_pub -u admin -P admin -h 127.0.0.1 -p 1883 -m 'ON' -t 999/set
Im trying to avoid using idx, because the objetive is manage sensors with an CustomID that i know.
Using this mechanism Im sure that my device is <xxxxx> is uniq and no need to "pre-configure" domoticz and then can send messaje like sensor/<xxxx>/state.
I saw some interesting information in this topic viewtopic.php?t=38403&sid=80dd06c4f7196 ... 7ce3cfc4dc but I don't understand if i'm doing something wrong or my concept of auto-discovery is not ok.
Then I made a "hack" changing custom command_topic and state_topic to domoticz/in but I have the same problem, can't update another information.
Code: Select all
mosquitto_pub -u admin -P admin -h 127.0.0.1 -p 1883 \
-m '{"unique_id": "001589", "name": "modulo_001589", "command_topic": "domoticz/in", "state_topic": "domoticz/in", "payload_on": "001589_on", "payload_off": "001589_off", "retain": true}' \
-t 'homeassistant/switch/8/config'
My idea is created switches/Lights (for example) automatically and after that send status update directly to ID (no idx). But the senros must be upadted (status) via Domoticz UI or MQTT message
...I'm trying to avoid create manually sensors or any manual human action.
Manual creation

This is an example, the topic domoticz/in has a "format" that can be send a lot of information like
{"command": "setcolbrightnessvalue", "idx": 2450, "hue": 274, "brightness": 40, "iswhite": false, "Batery" : 100 }
With AD Creation (self creation)

but when a send message to 999/set I dont have this "format"
I hope that can understand the idea and problem
another doc that I saw: https://wiki.domoticz.com/MQTT#Sending_a_Switch_Command
Thanks in advance!!!