This script used to work. Unfortunately I made some changes that required running this old script to restore the previous settings. I suspect one of the core updates ( maybe 0.115/0.116 ? ) changed something and I am unsure where to start looking.
I’m still experimenting with just the publshing one line to figure out what I’m doing wrong
the result I want is “speed_value_template”: “{{ value_json.FanSpeed }}”
and I’m trying ‘“speed_value_template”: “{{“value_json.FanSpeed”}}”’
which gives me “speed_value_template”: “value_json.FanSpeed” when I look at the published info using MQTT explorer
Just missing the {{ }} around “value_json.FanSpeed”
Ah ok,now I understand what you’re trying to do.
The problem is that since 0.115, data and data_template are equivalent, therefore it interprets your payload as a template and and gives you the error.
Thanks very much this has been big help pointing me in the right direction. Your “try like” suggestions unfortunately did not work. So I spun up a basic VM with 0.114.4, and by pointing to my main HA instance I was able to update MQTT and see the “device”. Updating the VM to 0.115 gave the same failures as you predicted.
I would still like to resolve in the event I need to run the script in the future. Any suggestions ? Here is my parred down script. Once it runs the final test is to verify the output in MQTT
It should be “speed_value_template”: “{{ value_json.FanSpeed }}”
I have several scripts designed to create entities via MQTT Discovery … just like what brucel1642 is doing. The payloads contain templates. You’ve made me realize that if I ever need to run them again, I will face the same problem.
This is one of those ‘edge cases’ where you don’t want the template to be evaluated. I have a feeling it was never envisioned when data was promoted to work just like data_template.
I’m not looking forward to modifying all those scripts to prevent their templates from being evaluated. Some of the templates were difficult enough to quote correctly without this additional layer of quoting complexity. This one comes to mind:
Burningstone, Thanks I now have it working. Wrapping with “{{ … }}” fixed it
123 Taras, Modifying the scripts wasn’t so bad for me. I kept a copy of the script in my packages folder in a “readable” format ie no escape \ characters. Then I pasted the payload into the script editor. When you go and look at the code in scripts.yaml with an file editor it shows all the escape characters it automatically added for you.
agreed, and we shouldn’t, This should really be fixed in the backend, and as a matter of fact, a fix for a related issue is coming (see my posts on the rest_command issues in another thread, and this GitHub issue)
That was the situation when data: did not attempt to render templates. Now that it does render them, I can only imagine what contortions will be needed to pass the payload without rendering.