Python Plugin: MqttMapper

Python and python framework

Moderator: leecollings

FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Let's try with:

Code: Select all

"MQTTsignal": {
"topic": "eas/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "value","multiplier": 1000}
}
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

2025-03-11 15:34:55.387 Error: MQTT mapper: Can't find >value< in >1.52300000190735<

Is there any reason it doesnt find the value? As we can see it does ...... or any other type that can read it?
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

I'm something lost...

Does the payload contain

Code: Select all

{"value": 1.52300000190735
or just

Code: Select all

1.52300000190735
?

Reading error message, I vote for the second...

In this case, try with

Code: Select all

"MQTTsignal": {
"topic": "eas/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "","multiplier": 1000}
}
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

2025-03-11 16:15:05.544 MQTT mapper: Received 45 bytes of data
2025-03-11 16:15:05.545 MQTT mapper: 30 2b 00 19 68 6f 6d 65 61 73 73 69 73 74 61 6e 74 2f 65 61 0+..homeassistant/ea
2025-03-11 16:15:05.545 MQTT mapper: 73 65 65 2f 70 6f 77 65 72 33 2e 32 36 39 39 39 39 39 38 30 see/power3.269999980
2025-03-11 16:15:05.545 MQTT mapper: 39 32 36 35 31 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 92651
2025-03-11 16:15:05.545 MQTT mapper: onMQTTPublish found homeassistant/easee/power, Device 'MQTT mapper - Car charge', message '3.26999998092651'
2025-03-11 16:15:05.545 MQTT mapper: Setting MQTT mapper - Car charge to 3270/3269.99998092651
2025-03-11 16:15:05.545 (MQTT mapper - Car charge) Updating device from 0:'' to have values 3270:'3269.99998092651'.

Its reading the value now but the display is still empty, we are making progress. I was a bit too early, see the error it through:

2025-03-11 16:17:09.467 Error: MQTT mapper: No SET parameters for MQTT mapper - Car charge/homeassistant/easee/power in ('MQTTsignal', {'topic': 'homeassistant/easee/power', 'type': '243', 'subtype': '29', 'switchtype': '0', 'mapping': {'item': '', 'multiplier': 1000}})

2025-03-11 16:31:13.292 MQTT mapper: onMQTTPublish found homeassistant/easee/power, Device 'MQTT mapper - Car charge', message '1.23800003528595'
2025-03-11 16:31:13.293 MQTT mapper: Setting MQTT mapper - Car charge to 1238/1238.00003528595
2025-03-11 16:31:13.293 (MQTT mapper - Car charge) Updating device from 0:'' to have values 1238:'1238.00003528595'.

2025-03-11 16:31:31.317 MQTT mapper: Received 45 bytes of data
2025-03-11 16:31:31.317 MQTT mapper: 30 2b 00 19 68 6f 6d 65 61 73 73 69 73 74 61 6e 74 2f 65 61 0+..homeassistant/ea
2025-03-11 16:31:31.317 MQTT mapper: 73 65 65 2f 70 6f 77 65 72 35 2e 30 38 35 39 39 39 39 36 35 see/power5.085999965
2025-03-11 16:31:31.317 MQTT mapper: 36 36 37 37 32 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 66772
2025-03-11 16:31:31.317 MQTT mapper: onMQTTPublish found homeassistant/easee/power, Device 'MQTT mapper - Car charge', message '5.08599996566772'
2025-03-11 16:31:31.317 MQTT mapper: Setting MQTT mapper - Car charge to 5086/5085.99996566772
2025-03-11 16:31:31.317 (MQTT mapper - Car charge) Updating device from 0:'' to have values 5086:'5085.99996566772'.

It seems to put the value back to 0? its hard to catch the values in a running log
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Depending on counter type you have chosen, you may have 2 displays : Widget could be daily usage (you have to wait a bit to see it incrementing), and total (located on text line, just under daily value). Total should be equal to value you see in the log, daily is computed from (total - first value of the day), and revert to zero at midnight (and first time you start it).
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

why do i keep getting error meassages:

2025-03-11 17:26:36.698 Error: MQTT mapper: No SET parameters for MQTT mapper - Car charge/homeassistant/easee/power in ('MQTTsignal', {'topic': 'homeassistant/easee/power', 'type': '243', 'subtype': '29', 'switchtype': '0', 'mapping': {'item': '', 'multiplier': 1000}})

what does the meassage No set parameters mean?
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

This happens when you try to set value using some script. In this case, Domoticz ask MqttMapper to update external value, but you don't give /set parameters (which indeed is normal in your case, as we don't normally set a counter).

Do you have any script trying to modify "MQQTTsignal" device?

FMI, did the counter increased?
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I did, but I don't know how to change is. Now the power is written power = 1.5634....
How must I change it?
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

I'm a bit lost...

Would it be possible to post here content of MqttMapper.json file?

Concerning topics, I'm still thinking that putting running values into a homeassistant sub-topic is a non sense.

An I still would like to see what's inside "eas" topic and its sub-topics , as stable values can probably be put here.
hjzwiers wrote: Tuesday 11 March 2025 18:03 I did, but I don't know how to change is. Now the power is written power = 1.5634....
How must I change it?
If you made any (LUA or dzVents) script modifying any MqttMapper involved devices, it could be a good idea to deactivate/delete them.
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

The status is as follows:

- I have a reading in MQTT. The values of power are displayed, the run up from 0.0 to 5.2 kw. This is correct. I have now added a format to the value to display ony three digit, which also works fine.
- I have moved it to "eas", it makes no difference
- I think the work in the automation in ha is done now

- In domoticz i can read the the value and see it in the logging, I use your latest suggestion:
"MQTTsignal": {
"topic": "homeassistant/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "","multiplier": 1000}
- The value it reads is not displayed, but it in the tab "Devices i can see the value of eg "5200, 0.0" in the data field

- So the only thing that is wrong is that it is not displaying the data, and I don't know why. Also the total energy is calculated wrong
- When I use the value with: sValue_CarCharger:match("([^;]+)") it reads the second value of the "0, 5102.0" so it is not placing the values correctly

local sValue_CarCharger = domoticz.devices('MQTT Car Charger').sValue
local values = {}
for value in sValue_CarCharger:gmatch("([^;]+)") do
table.insert(values, value)
end

local CarCharger = values[1] -- First value
local CarChargerTotal = values[2] -- Second value

2025-03-12 10:12:00.315 Status: dzVents: Current Car Charger: 5102.0 W
2025-03-12 10:12:00.315 Status: dzVents: Current Car Charger Total: nil W
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Could you try with :

Code: Select all

"MQTTsignal": {
"topic": "homeassistant/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "~*;~0","multiplier": 1000}
Item syntax `~*` means payload value and `;~0` means `;0`. MqttMapper device will be then loaded with the read value, multiplied by 1000, and followed by ;0. When receiving 1.234, device will contain `1234;0`.

Domoticz may perhaps not like getting a unique value, even if doc says that this second value is ignored when setting counter mode to "calculated".
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I tryed "~*;~0" and I also tryed only "~*"
I also changed the "swichtype" to "1" to force calculation of the total, they all have no effect

Is there another "type" I can try eg 248 subtype 1 ?

"MQTTsignal": {
"topic": "homeassistant/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "~*","multiplier": 1000}

Or something that reads a float value? Are there any updates I'm missing maybe?
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Setting switchType = 1 means "counter is a gas meter", probably not what you wanted.

FYI, here are switchtypes for meter :

Code: Select all

enum _eMeterType
{
	MTYPE_ENERGY = 0,		//0
	MTYPE_GAS,				//1
	MTYPE_WATER,			//2
	MTYPE_COUNTER,			//3
	MTYPE_ENERGY_GENERATED,	//4
	MTYPE_TIME,				//5
	MTYPE_END
};
To set "Calculated" mode, you have to specify it in options, when creating the device, adding :

Code: Select all

"options": {"EnergyMeterMode": "1" }
somewhere in device definition in MqttMapper JSON file.

As I don't known device's current state, it's better to delete it first and then set options on a fresh device.
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

All I really want is that the MQTT mapper heading works ....

"MQTTsignal": {
"topic": "homeassistant/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "~*","multiplier": 1000}

Is there any other type that I can try?
If I need the type "243" are there any settings I can try?
All I need to do is update my Mqttmapper.json and reset the the Mapper in Hardware settings. Somehow MQTT mapper is taking the value in homeassistant/easee/power wrong, although it is clear in MQTT explorer. The cummulative is also wrong in Devices, stuck at 5102.0

I reset mqttmapper already several times. I just deleted the value and ran Hardware update again, now the field is empty. I restarted a few times, and now the calculated values are ok, so it is working, but still nothing on the display.
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

@hjzwiers If you keep on answering without posting the real MQTT message with the value it will be extremely difficult for FlyingDomoticz to assist you.....
Stop talking about the log messages but just post the contents of the value topics.....
Perhaps a screenshot of the topic with the values you want in Domoticz will be better for now.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I have news. I am using:

"MQTTsignal": {
"topic": "homeassistant/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "~*","multiplier": 1000}

I checked on the phone and it displays the values! So my screen on the PC doesn't, i have no idea why not? An error is domoticz?
Attachments
Screenshot_20250312-171209.png
Screenshot_20250312-171209.png (318.28 KiB) Viewed 787 times
Screenshot 2025-03-12 171046.png
Screenshot 2025-03-12 171046.png (230.52 KiB) Viewed 787 times
Screenshot 2025-03-12 171006.png
Screenshot 2025-03-12 171006.png (175.04 KiB) Viewed 787 times
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

I did not ask for Domoticz info but MQTT Explorer info....

Edit: if you are talking about device "MQTT Car Charger" then empty is almost the same as 0.
So still MQTT data from MQTT explorer is needed to help you.
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: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

I really need to get the payload you inject into MqttMapper, as I more blond than less..

What I suspect is an illegal content (maybe a float with a "," instead of a ".").
hjzwiers
Posts: 242
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I added the automation code and a screenschot of MQTT Explorer, what else do you need?

By the way, the values are not read at the moment (with the same settings as yesterday)

"MQTTsignal": {
"topic": "homeassistant/easee/power",
"type": "243", "subtype": "29", "switchtype": "0",
"mapping": {"item": "~*;~0","multiplier": 1000}

alias: MQTT trigger car charge
description: >-
Publish current power and status when the car starts charging or when power
changes.
triggers:
- device_id: e22f8802c2e017fca694b4444f558df3
domain: easee
entity_id: sensor.ehr28hyj_status
type: charging
trigger: device
- device_id: e22f8802c2e017fca694b4444f558df3
domain: easee
entity_id: sensor.ehr28hyj_status
type: disconnected
trigger: device
- entity_id: sensor.ehr28hyj_power
trigger: state
conditions: []
actions:
- data:
message: >-
Power: {{ states('sensor.ehr28hyj_power') }}, Status: {{
states('sensor.ehr28hyj_status') }}
level: info
action: system_log.write
- data:
topic: homeassistant/easee/power
payload: "{{ states('sensor.ehr28hyj_power') | float | round(3) }}"
action: mqtt.publish
- data:
topic: homeassistant/easee/status
payload: "{{ states('sensor.ehr28hyj_status') }}"
action: mqtt.publish
mode: single
Attachments
Screenshot 2025-03-13 083014.png
Screenshot 2025-03-13 083014.png (100.32 KiB) Viewed 624 times
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Thanks for that!

I'm still thinking that publishing this kind of data in homeassistant sub-topics will lead to problems at some time, but do as you wish. In all cases, this as no effects on MqttMapper...

Concerning payload, float value seems to be the right one, with a decimal point (and not a comma as suspected).

Now, as we seems to got the right value in the right topic, let's see what's in Domoticz log regarding MqttMapper messages.

First, would it be possible to :
  • Delete MQTTsignal in domoticz (using "Setup/devices", finding MQTTsignal n the list, and clicking on the trash at the end of the line, then validating deletion?
  • Modify MqttMapper.json to add "options": {"EnergyMeterMode": "1" } line just after the "type" line?
  • Either restart Domoticz or the MqttMapper plug-in ("Setup" > "Hardware",select "MqttMapper" line, and click on "Modify" button without changing anything
  • Extract part of Domoticz log related to MqttMapper and put it here
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest