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.