tasmota / decode-config

Backup/restore and decode configuration tool for Tasmota
GNU Lesser General Public License v3.0
211 stars 32 forks source link

array 'ds3502_state' couldn't restore, format has changed #84

Closed reini-1 closed 7 months ago

reini-1 commented 7 months ago

Describe the bug

I cannot restore downloaded json of a Nous A1 Plug. I would like to download the json, change something with e.g. jq or ansible and upload the modified config but I already get an error when I try to upload the downloaded configuration without changes.

So ideally I would do something like this:

$ decode-config --source nousa1t01 --json-show-pw | jq '.hostname = "foo"' | decode-config --source nousa1t01 --restore-file -

But there are two problems:

  1. There is an error with the original downloaded config when I want to upload it
  2. decode-config did not support getting the config file from stdin

The second can be workaround with a temporary file but for the first I have no idea to fix this. It would be nice if decode-config would also accept the restore file from stdin.

To Reproduce

$ decode-config --source nousa1t01 --json-show-pw > new_config.json
$ decode-config --source nousa1t01 --restore-file new_config.json --dry-run
INFO: Load data by http from device 'nousa1t01'
WARNING 9: file './new_config.json' - {'ds3502_state': 255} (valid range exceeding)
Premature exit - #9 Restore data error
WARNING 9 (@5444): file './new_config.json' array 'ds3502_state' couldn't restore, format has changed! Restore value contains <class 'list'> but an array of size [4] is expected
Premature exit - #9 Restore data error

$ decode-config --source nousa1t01 | jq .ds3502_state
[
  255,
  0,
  0,
  0
]

$ jq .ds3502_state new_config.json 
[
  255,
  0,
  0,
  0
]

Expected behavior

Config would be uploaded and updated.

Version Information

$ decode-config --version --debug
decode-config v13.3.0.0 by Norbert Richter nr@prsolution.eu

Script:   decode-config.py
Version:  13.3.0.0
Python:   3.10.13
Platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35 - x86_64
OS:       Linux 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023
Time:     2024-02-11 15:27:15

System' information of your Tasmota data

$ decode-config --source nousa1t01 -g System --json-indent 2
{
  "bootcount": 309, 
  "bootcount_reset_time": 1630802383, 
  "cfg_crc": "0x75d6", 
  "cfg_crc32": "0xbc8932bc", 
  "cfg_holder": 4617, 
  "cfg_size": 4096, 
  "cfg_timestamp": 1707607040, 
  "header": {
    "data": {
      "crc": "0x90ca", 
      "crc32": "0xbc8932bc", 
      "hardware": "ESP82", 
      "size": 4096, 
      "version": {
        "id": "0xd030000", 
        "name": "13.3.0"
      }
    }, 
    "env": {
      "platform": "Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35", 
      "python": "3.10.13", 
      "script": "decode-config.py v13.3.0.0", 
      "system": "Linux x86_64 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023"
    }, 
    "template": {
      "crc": "0x75d6", 
      "crc32": "0xbc8932bc", 
      "size": 4096, 
      "version": {
        "id": "0xd030000", 
        "name": "13.3.0"
      }
    }, 
    "timestamp": "2024-02-10 23:17:20"
  }, 
  "version": "0xd030000"
}

$ decode-config --source nousa1t01 | jq '.ota_url'
"http://ota.tasmota.com/tasmota/release/tasmota.bin.gz"

Additional context

In the end I would create an Ansible playbook, that first downloads the configuration decode-config, changes/updates something according to the Ansible inventory and than uploads the new configuration with decode-config if something has changed.

reini-1 commented 7 months ago

I think the Nous A1 did not have this poti functionality and default tasmota did not have this compiled in as I found in the documentation/posting, so I think it is not a problem to change the value to something in the limits:

$ decode-config --source nousa1t01 --json-show-pw | jq '.ds3502_state = [127,0,0,0]' | jq '.hostname = "foo"'
 > new_config.json

but than the next value error pops up:

$ decode-config --source nousa1t01 --restore-file new_config.json --dry-run
INFO: Load data by http from device 'nousa1t01'
WARNING 9: file './new_config.json' - {'energy_kWhexport_ph': -17034004} (valid range exceeding)
Premature exit - #9 Restore data error
WARNING 9 (@5444): file './new_config.json' array 'energy_kWhexport_ph' couldn't restore, format has changed! Restore value contains <class 'list'> but an array of size [3] is expected
Premature exit - #9 Restore data error

jq .energy_kWhexport_ph new_config.json 
[
  8895872,
  -17034004,
  -1107109
]

This is also no feature of default image: https://tasmota.github.io/docs/Smart-Meter-Interface/

Is there something to ignore errors on values the firmware did not support?

reini-1 commented 7 months ago

After fixing this value also to something accepted, restore worked:

$ decode-config --source nousa1t01 --json-show-pw | jq '.ds3502_state = [127,0,0,0]' | jq '.energy_kWhexport_ph = [0,0,0]' | jq '.hostname = "foo"' > new_config.json

$ jq .energy_kWhexport_ph new_config.json 
[
  0,
  0,
  0
]

$ decode-config --source nousa1t01 --restore-file new_config.json --dry-run
INFO: Load data by http from device 'nousa1t01'
INFO: * Simulating Restore successful to device 'nousa1t01' from './new_config.json'

$ decode-config --source nousa1t01 --restore-file new_config.json
INFO: Load data by http from device 'nousa1t01'
INFO: Restore successful to device 'nousa1t01' from './new_config.json'

$ decode-config --source nousa1t01 --json-show-pw | jq '.hostname, .ds3502_state, .energy_kWhexport_ph'
"foo"
[
  127,
  0,
  0,
  0
]
[
  8895872,
  -17034004,
  -1107109
]

The value of energy_kWhexport_ph is restored on the device to the original values again.

curzon01 commented 7 months ago

These kinds of errors (values are outside valid ranges) originally come from junk within Tasmota setting (due to updates or other previous issues). Such device configurations should be reset once (e.g. Reset 2) to get an clean valid Tasmota config. Alternatively use decode-config parameter -w to suppress exit for warnings.