MQTT autodiscovery

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

Moderator: leecollings

Post Reply
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

MQTT autodiscovery

Post by Piacco »

I’m using pv2mqtt to read out my APsystems solar panels via MQTT autodiscovery. The output is shown below. I receive all values in Domoticz except for the Wh value.
I don't know why the Wh value isn’t showing up in Domoticz an how can I fix this?

Code: Select all

{
  "device": {
    "identifiers": [
      "xxxxxxxx"
    ],
    "manufacturer": "APsystems",
    "model": "DS3",
    "name": "Inverter xxxxxxxx",
    "sw_version": "V2284"
  },
  "device_class": "energy",
  "enabled_by_default": true,
  "force_update": true,
  "name": "Energy",
  "state_class": "total_increasing",
  "state_topic": "pv2mqtt/inverter/xxxxxxxx",
  "unit_of_measurement": "kWh",
  "unique_id": "pv2mqtt_xxxxxxxx_WH",
  "value_template": "{{ value_json.WH / 1000 | round(3) }}"
}
Output of the mqtt topic

Code: Select all

{"AphA": 0.17, 
"AphB": null, 
"AphC": null, 
"PhVphA": 232.0, 
"PhVphB": null, 
"PhVphC": null, 
"W": 8.0, 
"VA": 40.7, 
"VAr": 40.0, 
"WH": 470.0, 
"PF": 0.196, 
"Hz": 50.0, 
"TmpCab": 17.0, 
"TmpSnk": null, 
"TmpTrns": null, 
"TmpOt": null}
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: MQTT autodiscovery

Post by waltervl »

Probably because there are calculations in the value template. Domoticz does not support that.

Code: Select all

"value_template": "{{ value_json.WH / 1000 | round(3) }}"
For Domoticz this probably would be enough:

Code: Select all

  "unit_of_measurement": "Wh"
"value_template": "{{ value_json.WH }}"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT autodiscovery

Post by Piacco »

I can't change the template, so this has to be done with node red or are there other solutions?
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: MQTT autodiscovery

Post by waltervl »

Or ask pv2mqtt to change the config topic. Or modify the application yourself.
You can send your own modified config topic with for example MQTT explorer or mosquito_pub to test what is the correct config topic
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: MQTT autodiscovery

Post by waltervl »

When I look in the file pv2mqtt.py the config topic is hardcoded so you can change it yourself to test.
https://github.com/MartijnVdS/pv2mqtt/b ... pv2mqtt.py
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT autodiscovery

Post by Piacco »

Tanks, I've changed the pv2mqtt.py and rebuild the container, the value is now send to Domoticz, I've only contvert it from Wh to kWh, so this can be done with DzVents.
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: MQTT autodiscovery

Post by waltervl »

You shouldnt. Domoticz needs Wh values, not kwh. Domoticz does the calculation to kwh for you.
So change the value template and the unit of measure as I already explained.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT autodiscovery

Post by Piacco »

I’ll have a closer look at it tomorrow, but this is how Domoticz is receiving the values.
These are day value's, this must be 0,474kWh 0,816kWh and 0,937kWh
Domoticz.JPG
Domoticz.JPG (19.7 KiB) Viewed 239 times
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: MQTT autodiscovery

Post by waltervl »

You because you did not do what I advised......
Change into the pv2mqtt.py config topic

Code: Select all

"unit_of_measurement": "Wh"
"value_template": "{{ value_json.WH }}"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT autodiscovery

Post by Piacco »

Oops, my reading skills are not the best! You were right—I've switched it to 'Wh' and voilà, the values are finally behaving. Thanks again!" 😄
Piacco
Posts: 81
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT autodiscovery

Post by Piacco »

The device is showing up as General kWh, Electricity (instant and counter), these device needs two value's instant and counter, how do i get the instant value into the device? The value instant W is available.

Code: Select all

{
  "device": {
    "identifiers": [
      "xxxxxxx"
    ],
    "manufacturer": "APsystems",
    "model": "DS3",
    "name": "Inverter xxxxxxx",
    "sw_version": "V2284"
  },
  "device_class": "power",
  "enabled_by_default": true,
  "force_update": true,
  "name": "Power",
  "state_class": "measurement",
  "state_topic": "pv2mqtt/inverter/xxxxxxx",
  "unit_of_measurement": "W",
  "unique_id": "pv2mqtt_xxxxxxx_W",
  "value_template": "{{ value_json.W }}"
}
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: MQTT autodiscovery

Post by waltervl »

I have no Idea how the counter value should be added with MQTT autodiscover.
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: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: MQTT autodiscovery

Post by FlyingDomotic »

Neither me... but if you can't find a way with MQTT Autodiscovery, yo may have a look at https://github.com/FlyingDomotic/domoti ... per-plugin.
An example of MqttMapper configuration file could be:

Code: Select all

"My KWh counter" : {
		"topic": "pv2mqtt/inverter/xxxxxxxx",
		"type": "248", "subtype": "1", "switchtype": "0",
		"mapping": {"item": "W;WH"}
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest