joba-1 / Tasmoticz

Domoticz MQTT autodiscovery plugin for Tasmota devices
MIT License
25 stars 18 forks source link

errors on new version of tasmota #23

Open megamarco833 opened 3 years ago

megamarco833 commented 3 years ago

Hi i'm using tasmoticz since years without any issue.

right now i update my firmware version of tasmota from 9.1 to latest 9.4.0.3 and i start to see this errors on log (below reported)

just and introduction: with new tasmota firmware it's possible to use PCF8574 for output(like in the previous firmware) but also for input (new). I not change my hardware setup: nodemcu esp8266 + n°2 pcf8574 (total 16 port set as 16 outputs relay. so all port set to output, none for input, so nothing changed, all the same like in 9.1 firmware)

the new tasmota firmware is compiled to enable pcf8574 using gitpod enabling this lines inside my_user_config.h

  #define USE_PCF8574                            // [I2cDriver2] Enable PCF8574 I/O Expander (I2C addresses 0x20 - 0x26 and 0x39 - 0x3F) (+1k9 code)
    #define USE_PCF8574_SENSOR                   // enable PCF8574 inputs and outputs in SENSOR message
    #define USE_PCF8574_DISPLAYINPUT             // enable PCF8574 inputs display in Web page
    #define USE_PCF8574_MQTTINPUT                // enable MQTT message & rule process on input change detection : stat/%topic%/PCF8574_INP = {"Time":"2021-03-07T16:19:23+01:00","PCF8574-1_INP":{"D1":1}}

with the new tasmota i see these errors:


 2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) 'onMessage' failed 'NameError'.
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 183 in '/home/pi/domoticz/plugins/Tasmoticz/plugin.py', function onMessage
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 127 in '/home/pi/domoticz/plugins/Tasmoticz/plugin.py', function onMessage
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 184 in '/home/pi/domoticz/plugins/Tasmoticz/mqtt.py', function onMessage
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 348 in '/usr/lib/python3.7/json/__init__.py', function loads
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 337 in '/usr/lib/python3.7/json/decoder.py', function decode
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 355 in '/usr/lib/python3.7/json/decoder.py', function raw_decode
2021-05-12 12:25:50.731 Error: tasmoticz: (tasmoticz) ----> Line 35 in '/usr/lib/python3.7/json/decoder.py', function __init__ 

these errors are not limiting the usage, tasmoticz still working and i'm able to turn on/off relays from domoticz and tasmota is linked, but i continue to see these errors inside the GUI.

If i revert back with firmware 9.1 i do not see any errors.

Again, firmware 9.1 and 9.3.0.4 share the same hardware and same settings.

how to reproduce: 1) compile tasmota with enabling the PCF8574 and set the port as output. 2) if you still have tasmoticz on domoticz, go in setup-> hardware-> click on tasmoticz pluging and press "update" 3) look at GUI web page for logs and you will see the error messages.

Can you please have a look on it? thanks!

joba-1 commented 3 years ago

Hi, nice to know the plugin generally works for you. Two remarks: 1) tasmoticz only does the detection of tasmota devices and creates domoticz devices from it. It has nothing to do with the operation of the switch. It could be you would have problems detecting new devices. Have you checked this? 2) There seems to be a json message arriving via mqtt from the updated tasmota devices that my plugin does not properly cope with. It will help to see mqtt messages that are sent from tasmota at the time the error message appears.

megamarco833 commented 3 years ago

hi discover something, https://tasmota.github.io/docs/PCF8574/#pcf8574-in-sensor-message

PCF8574 in SENSOR message~

Enabling USE_PCF8574_SENSOR adds a PCF8574-xx field into the JSON payload of the tele/topic/SENSOR message. The form of the message is: 13:19:07.459 MQT: tele/tasmota_156/SENSOR = {"Time":"2021-05-12T13:19:07","PCF8574-1":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1,"PCF8574-2":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":0,"D5":1,"D6":1,"D7":1}}

i set in tasmoticz: image

i try to compile again the firmware but this time inside my_user_config.h i not enable : #define USE_PCF8574_SENSOR // enable PCF8574 inputs and outputs in SENSOR message

in this case i do not receive the errors.

But maybe could be fixed the usage of tasmota "sensor" option inside tasmoticz? could be useful to listen also at "tele/%topic%/SENSOR" to menage also this new implementation?

joba-1 commented 3 years ago

I suspect a world record here: fastest time in delivering requested log output :)

The SENSOR message is the culprit - it actually is not valid JSON. A curly brace after the first sensor data is missing. I'm sure the people over at tasmota can help you with that.

megamarco833 commented 3 years ago

I suspect a world record here: fastest time in delivering requested log output :)

ahahah no no it is just lucky that we was write simultaneously i suspect :D

The SENSOR message is the culprit - it actually is not valid JSON. A curly brace after the first sensor data is missing. I'm sure the people over at tasmota can help you with that.

mmm sorry where is the curly brace missing!? 13:19:07.459 MQT: tele/tasmota_156/SENSOR = {"Time":"2021-05-12T13:19:07","PCF8574-1":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1,"PCF8574-2":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":0,"D5":1,"D6":1,"D7":1}}

thanks

joba-1 commented 3 years ago

I suspect a world record here: fastest time in delivering requested log output :)

ahahah no no it is just lucky that we was write simultaneously i suspect :D :)

mmm sorry where is the curly brace missing!? 13:19:07.459 MQT: tele/tasmota_156/SENSOR = {"Time":"2021-05-12T13:19:07","PCF8574-1":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1###right here###,"PCF8574-2":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":0,"D5":1,"D6":1,"D7":1}}

thanks

joba-1 commented 3 years ago

I guess, this is how it should look like:

echo '{"Time":"2021-05-12T13:19:07","PCF8574-1":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1},"PCF8574-2":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":0,"D5":1,"D6":1,"D7":1}}' | python -m json.tool
{
    "Time": "2021-05-12T13:19:07",
    "PCF8574-1": {
        "D0": 1,
        "D1": 1,
        "D2": 1,
        "D3": 1,
        "D4": 1,
        "D5": 1,
        "D6": 1,
        "D7": 1
    },
    "PCF8574-2": {
        "D0": 1,
        "D1": 1,
        "D2": 1,
        "D3": 1,
        "D4": 0,
        "D5": 1,
        "D6": 1,
        "D7": 1
    }
}
megamarco833 commented 3 years ago

sorry for that, now i perfectly understand, and you are fully right! i will try to talk with tasmota.

do you think that ones it will be fixed could be useful for your plugin use the "sensor" json?

megamarco833 commented 3 years ago

hi, now the json is fixed:

previous (wrong) 13:19:07.459 MQT: tele/tasmota_156/SENSOR = {"Time":"2021-05-12T13:19:07","PCF8574-1":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1,"PCF8574-2":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":0,"D5":1,"D6":1,"D7":1}}

new(correct) 18:41:59.537 MQT: tele/tasmota_156/SENSOR = {"Time":"2021-05-12T18:41:59","PCF8574-1":{"D0":1,"D1":0,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1},"PCF8574-2":{"D0":1,"D1":1,"D2":1,"D3":1,"D4":1,"D5":1,"D6":1,"D7":1}}}

thanks for help me on recognize the error.

i tested with tasmoticz plugin and now it works without any issue.


i take the take advantage of this topic and json issue to ask, if it's possible and feasible to look at json of shutter in tasmota to menage in domoticz.

it could be great!!!!

inside json there is the percentage and we can link domoticz blinde with percentage to firmware with tasmota. here an example of json from tasmota for blind:

19:04:12.913 MQT: stat/tasmota_blind_new/RESULT = {"POWER2":"ON"}
19:04:12.917 MQT: stat/tasmota_blind_new/POWER2 = ON
19:04:12.921 MQT: stat/tasmota_blind_new/RESULT = {"ShutterPosition1":37}
19:04:12.980 MQT: stat/tasmota_blind_new/RESULT = {"Shutter1":{"Position":57,"Direction":-1,"Target":37}}
19:04:13.724 MQT: stat/tasmota_blind_new/RESULT = {"Shutter1":{"Position":52,"Direction":-1,"Target":37},"Shutter2":{"Position":27,"Direction":0,"Target":27}}
19:04:14.728 MQT: stat/tasmota_blind_new/RESULT = {"Shutter1":{"Position":45,"Direction":-1,"Target":37},"Shutter2":{"Position":27,"Direction":0,"Target":27}}
19:04:15.758 MQT: stat/tasmota_blind_new/RESULT = {"Shutter1":{"Position":38,"Direction":-1,"Target":37},"Shutter2":{"Position":27,"Direction":0,"Target":27}}
19:04:15.951 MQT: stat/tasmota_blind_new/RESULT = {"POWER2":"OFF"}
19:04:15.958 MQT: stat/tasmota_blind_new/POWER2 = OFF
19:04:16.466 MQT: stat/tasmota_blind_new/SHUTTER1 = 37
19:04:16.473 MQT: stat/tasmota_blind_new/RESULT = {"Shutter1":{"Position":37,"Direction":0,"Target":37}}

what do you think? tasmoticz could look at: 19:04:16.466 MQT: stat/tasmota_blind_new/SHUTTER1 = 37 stat/%topic%/SHUTTER1 = 37 => shutter1 is at 37% to update domoticz when command is issued by tasmota

and when the command is send by domoticz, : nValue=0-->total Closed nValue=1-->>total Opened nValue=2-->>level=sValue

so tasmoticz should send for set percentage (level): cmnd/<topic>/shutterposition <svalue1>
svalue1 contain the percentage of positioning

when total close or total open domoticz use (looking at nValue): cmnd/<topic>/shutterOpen <number of blind to control> cmnd/<topic>/shutterClose <number of blind to control>

could be used to expand the functionality of tasmoticz?

megamarco833 commented 3 years ago

ciao @joba-1 i tested the new release of tasmota, and now they fixed the output json and it's working with your plugin tasmoticz :) thanks for highlight the mistake inside tasmota :)

did you get the chance to have a look at second part of my post? can you look at json response of blind state? can tasmoticz plugin menage also this ? :)

joba-1 commented 3 years ago

good to know that it works now.

Adding shutter/blinds support is definitely possible, but my time schedule does not allow me to add new features - especially if I don't have devices to test it with (and since some time already). So if there is a PR I‘ll certainly evaluate it but other than that I can just fix bugs and add new sensor types occasionally.