arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.04k stars 4.78k forks source link

Berry script not returning sensors values in a given condition #21314

Closed rp2019433 closed 5 months ago

rp2019433 commented 5 months ago

PROBLEM DESCRIPTION

Board: ESP32

Sensors attached to ESP32:

image

When running the Berry script below in version 13.4.0, Tasmota does not return information for any sensor.

import json
var sensors = json.load(tasmota.read_sensors())
print(sensors)

tasmota-b

If I downgrade version to 13.0.0, Tasmota returns some information, but without SGP sensor:

tasmota-a

If I remove BME680 and SGP40, and run Berry script in version 13.4.0, Analog sensors values are returned:

tasmota-c

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

15:39:40.263 CMD: Backlog Template; Module; GPIO 255
15:39:40.288 RSL: RESULT = {"NAME":"ESP32-DevKit","GPIO":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,1,1,1,1,1,0,0,1],"FLAG":0,"BASE":1}
15:39:40.531 RSL: RESULT = {"Module":{"1":"ESP32-DevKit"}}
15:39:40.760 RSL: RESULT = {"GPIO0":{"0":"None"},"GPIO1":{"0":"None"},"GPIO2":{"0":"None"},"GPIO3":{"0":"None"},"GPIO4":{"0":"None"},"GPIO5":{"0":"None"},"GPIO6":{"0":"None"},"GPIO7":{"0":"None"},"GPIO8":{"0":"None"},"GPIO9":{"0":"None"},"GPIO10":{"0":"None"},"GPIO11":{"0":"None"},"GPIO12":{"0":"None"},"GPIO13":{"0":"None"},"GPIO14":{"0":"None"},"GPIO15":{"0":"None"},"GPIO16":{"0":"None"},"GPIO17":{"0":"None"},"GPIO18":{"0":"None"},"GPIO19":{"0":"None"},"GPIO20":{"0":"None"},"GPIO21":{"640":"I2C SDA1"},"GPIO22":{"608":"I2C SCL1"},"GPIO23":{"0":"None"},"GPIO24":{"0":"None"},"GPIO25":{"0":"None"},"GPIO26":{"0":"None"},"GPIO27":{"0":"None"},"GPIO32":{"0":"None"},"GPIO33":{"0":"None"},"GPIO34":{"4705":"ADC Input2"},"GPIO35":{"4704":"ADC Input1"},"GPIO36":{"0":"None"},"GPIO37":{"0":"None"},"GPIO38":{"0":"None"},"GPIO39":{"0":"None"}}
- [ ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
- [ ] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:

TO REPRODUCE

Steps to reproduce the behavior:

Described above.

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen.

When running commands below, all sensors values should be returned.

import json
var sensors = json.load(tasmota.read_sensors())
print(sensors)

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

Screenshots inserted above.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

sfromis commented 5 months ago

That nil could be a symptom of invalid JSON, but you did not show the output from tasmota.read_sensors() without also doing the json.load().

rp2019433 commented 5 months ago

Hi. I forgot to mention that. tasmota.read_sensors() without json.load() works properly.

import json
var sensors=tasmota.read_sensors()
print(sensors)

image

rp2019433 commented 5 months ago

Indeed. There is an invalid JSON output.

This is the output generated for the code below:

var sensors=tasmota.read_sensors()
print(sensors)

{"Time":"2024-05-01T16:20:04","ANALOG":{"A1":2536,"A2":974},"BME680":{"Temperature":31.5,"Humidity":100.0,"DewPoint":31.5,"Pressure":967.6,"Gas":46.99},"SGP40":{"VOC_Raw":28304,,"TVOC":235,},"Custom":{"Battery Voltage":4.10},"PressureUnit":"hPa","TempUnit":"C"}

sfromis commented 5 months ago

Yeah, there was an error in the driver, producing too many commas. Fixed a month ago in https://github.com/arendst/Tasmota/issues/21084

If you upgrade to the development build, the fix is included.

Beware that your "Custom" sensor produces a JSON key with a space. While this is not technically invalid, it can cause trouble with some tools. Hence, this style is generally avoided.

Jason2866 commented 5 months ago

Closing since already fixed in development branch