Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use escaped Query, because it will break templating. #14146

Merged
merged 2 commits into from
Jun 1, 2024

Conversation

pmec
Copy link
Contributor

@pmec pmec commented May 31, 2024

While writing a custom http charger, I found that when doing templating on a url query it would be escaped and wouldn't work.
Example of what was the result:
/write/Paused=%7B%7Bif%20.enable%7D%7D0%7B%7Belse%7D%7D1%7B%7Bend%7D%7D
What should be:
/write/Paused=1

@andig andig merged commit 4f88806 into evcc-io:master Jun 1, 2024
6 checks passed
@andig
Copy link
Member

andig commented Jun 1, 2024

Good catch, thank you!

@Neisi
Copy link

Neisi commented Jun 3, 2024

Mhmm....das führt jetzt aber u.a. bei Tasmota-URLs zum falschen Ergebnis oder?
uri: http://xxxxxx/cm?cmnd=Status%208
->
GET http://xxxxx/cm?cmnd=Status 8
ausgeführt wird dann nur GET http://xxxx/cm?cmnd=Status (also falscher Status wird abgerufen)

@andig
Copy link
Member

andig commented Jun 3, 2024

Sieht so aus :(. @pmec seems we need to revert this and think a little more about how to proceed?

@andig
Copy link
Member

andig commented Jun 4, 2024

@Neisi where do you get these Tasmota URLs from? Could you share a log file?

@VolkerK62
Copy link
Contributor

template: tasmota-sml and template: tasmota are still working

- name: tasmota
  type: template
  template: tasmota-sml
  host: 192.168.178.27
  usage: grid
wsl@DESKTOP-7RU7VSU:~$ evcc meter tasmota --log trace
[main  ] INFO 2024/06/04 09:19:34 evcc 0.126.6 (59fafccb)
[main  ] INFO 2024/06/04 09:19:34 using config file: /home/wsl/evcc.yaml
[db    ] INFO 2024/06/04 09:19:34 using sqlite database: /home/wsl/.evcc/evcc.db
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="settings" -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "settings" AND sql IS NOT NULL order by type = "table" desc 1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT * FROM `settings` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT * FROM `settings` 28 <nil>
[mqtt  ] INFO 2024/06/04 09:19:35 connecting evcc-1233450514 at tcp://raspberrypi:1883
[mqtt  ] DEBUG 2024/06/04 09:19:35 tcp://raspberrypi:1883 connected
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="device_details" -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="devices" -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="configs" -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "configs" AND sql IS NOT NULL order by type = "table" desc 1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT * FROM `configs` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="config_details" -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "config_details" AND sql IS NOT NULL order by type = "table" desc 2 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT * FROM `config_details` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%CONSTRAINT ""fk_configs_details"" %" OR sql LIKE "%CONSTRAINT fk_configs_details %" OR sql LIKE "%CONSTRAINT `fk_configs_details`%" OR sql LIKE "%CONSTRAINT [fk_configs_details]%" OR sql LIKE "%CONSTRAINT                                                            fk_configs_details       %") -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type = "index" AND tbl_name = "config_details" AND name = "idx_unique" -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%CONSTRAINT ""fk_devices_details"" %" OR sql LIKE "%CONSTRAINT fk_devices_details %" OR sql LIKE "%CONSTRAINT `fk_devices_details`%" OR sql LIKE "%CONSTRAINT [fk_devices_details]%" OR sql LIKE "%CONSTRAINT                                                            fk_devices_details       %") -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%""device_id"" %" OR sql LIKE "%device_id %" OR sql LIKE "%`device_id`%" OR sql LIKE "%[device_id]%" OR sql LIKE "%     device_id       %") -1 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT * FROM `config_details` WHERE `config_details`.`config_id` IN (1,3) 7 <nil>
[db    ] TRACE 2024/06/04 09:19:35 SELECT * FROM `configs` WHERE `configs`.`class` = 2 ORDER BY id 2 <nil>
[tasmota] TRACE 2024/06/04 09:19:35 GET http://192.168.178.27/cm?cmnd=Status+8&password=&user=
[tasmota] TRACE 2024/06/04 09:19:35 {"StatusSNS":{"Time":"2024-06-04T08:19:35","SML":{"Power_curr":-1428,"Total_in":10804,"Total_out":19247}}}
Power:  -1428W
Energy: 10804.0kWh

the problem is only with custom configuration

- name: tasmota_test
  type: custom
  power:
    source: http
    uri: http://192.168.178.27/cm?cmnd=Status%208
    jq: .StatusSNS.SML.Power_curr
wsl@DESKTOP-7RU7VSU:~$ evcc meter tasmota_test --log trace
[main  ] INFO 2024/06/04 09:31:22 evcc 0.126.6 (59fafccb)
[main  ] INFO 2024/06/04 09:31:22 using config file: /home/wsl/evcc.yaml
[db    ] INFO 2024/06/04 09:31:22 using sqlite database: /home/wsl/.evcc/evcc.db
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="settings" -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "settings" AND sql IS NOT NULL order by type = "table" desc 1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT * FROM `settings` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT * FROM `settings` 28 <nil>
[mqtt  ] INFO 2024/06/04 09:31:22 connecting evcc-1718462572 at tcp://raspberrypi:1883
[mqtt  ] DEBUG 2024/06/04 09:31:22 tcp://raspberrypi:1883 connected
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="devices" -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="device_details" -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="configs" -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "configs" AND sql IS NOT NULL order by type = "table" desc 1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT * FROM `configs` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="config_details" -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "config_details" AND sql IS NOT NULL order by type = "table" desc 2 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT * FROM `config_details` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%CONSTRAINT ""fk_configs_details"" %" OR sql LIKE "%CONSTRAINT fk_configs_details %" OR sql LIKE "%CONSTRAINT `fk_configs_details`%" OR sql LIKE "%CONSTRAINT [fk_configs_details]%" OR sql LIKE "%CONSTRAINT                                                            fk_configs_details       %") -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type = "index" AND tbl_name = "config_details" AND name = "idx_unique" -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%CONSTRAINT ""fk_devices_details"" %" OR sql LIKE "%CONSTRAINT fk_devices_details %" OR sql LIKE "%CONSTRAINT `fk_devices_details`%" OR sql LIKE "%CONSTRAINT [fk_devices_details]%" OR sql LIKE "%CONSTRAINT                                                            fk_devices_details       %") -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%""device_id"" %" OR sql LIKE "%device_id %" OR sql LIKE "%`device_id`%" OR sql LIKE "%[device_id]%" OR sql LIKE "%     device_id       %") -1 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT * FROM `config_details` WHERE `config_details`.`config_id` IN (1,3) 7 <nil>
[db    ] TRACE 2024/06/04 09:31:22 SELECT * FROM `configs` WHERE `configs`.`class` = 2 ORDER BY id 2 <nil>
[http  ] TRACE 2024/06/04 09:31:22 GET http://192.168.178.27/cm?cmnd=Status 8
[http  ] TRACE 2024/06/04 09:31:22 {"Status":{"Module":0,"DeviceName":"cmatic","FriendlyName":["cmatic"],"Topic":"cmatic_51ACD8","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0}}
Power: strconv.ParseFloat: parsing "<nil>": invalid syntax

@andig
Copy link
Member

andig commented Jun 4, 2024

Reverted

@andig
Copy link
Member

andig commented Jun 4, 2024

@pmec I'm not quite sure what's wrong here and how to properly fix it. Does your use case work before 81ba7dc#diff-39f5c63d71a9df557ad9cf95d2cb3d610659c681fcdc600e535add1972e970dd?

@osulivanDE
Copy link

osulivanDE commented Jun 4, 2024

I think i experience the same Problem with the latest update (126.6)
EVCC can´t log in to my tasmota anymore and therefore doesn´t start.
I might not use the right way to call my values and might update to the regular "tasmota-sml" template soon but since this needs some updates on some other parts of HA and my ESS System i stay on 126.4.

Here is my config:

  - name: Tasmota
    type: custom
    power:
        source: http
        uri: http://192.168.2.95/cm?cmnd=Status+8&password=PASSWORD&user=admin
        jq: .StatusSNS.MT681.Power_curr

@EIBHomeControl

This comment was marked as resolved.

@andig
Copy link
Member

andig commented Jun 5, 2024

Issue is fixed in master

@evcc-io evcc-io locked as off-topic and limited conversation to collaborators Jun 5, 2024
@evcc-io evcc-io unlocked this conversation Jun 5, 2024
@andig
Copy link
Member

andig commented Jun 5, 2024

The question here is still: how can we not escape template variables when calling this function? Should we remove this function instead and rely on fully correct config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants