Doubt with sensor update (the egg or the chicken)

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

Post Reply
jpradoar
Posts: 12
Joined: Thursday 23 May 2024 2:18
Target OS: Linux
Domoticz version: stable
Location: Argentina
Contact:

Doubt with sensor update (the egg or the chicken)

Post by jpradoar »

Hi all, Jtan here.
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'
from here all ok again, but the problem is when I try to update "light" from domoticz UI the UI dont "send" appropriate message and then to turn-on or turn-off the light I need to send

Code: Select all

 mosquitto_pub  -u admin -P admin -h 127.0.0.1 -p 1883 -m 'ON' -t  999/set 
This is a problem because the uniq "trigger" is "ON or "OFF" and if a need send more information like battery or something similar I cant.
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
Image
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)
Image
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!!!
User avatar
waltervl
Posts: 5398
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Doubt with sensor update (the egg or the chicken)

Post by waltervl »

I do not understand your question completely.
So does the MQTT AD config topic create a device ion Domoticz?
Can you switch the device in Domoticz from MQTT with ON/OFF payload?

You can also look at the ESPHome library as that integrates MQTT AD and test how it configures the MQTT AD config, set and state topics for a specific device type (eg binary sensor). https://esphome.io/components/mqtt.html ... -assistant
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 328
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Doubt with sensor update (the egg or the chicken)

Post by FlyingDomotic »

You may have a look at MqttMapper (https://github.com/FlyingDomotic/domoti ... per-plugin).

Giving a definition in a json file, it'll create a Domoticz device, and will update it each time you'll change data in MQTT. You may also change device in Domoticz, and forward the change in MQTT, either in the same topic, or another one. You don't have to specify IDX somewhere.

Should you have multiple Domoticz instances, just duplicate (part of) json configuration file.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest