2023-02-26 20:38:46.578 ERROR (MainThread) [homeassistant.components.shell_command] Error rendering command template: UndefinedError: float object has no element 88
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 457, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1984, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py", line 303, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: float object has no element 88
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/shell_command/__init__.py", line 51, in async_service_handler
rendered_args = args_compiled.async_render(
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 459, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: float object has no element 88
What @tom_l said: it’s using {{ ip }} rather than {{ 192.168.88.229 }} that is important though, rather than the quotes.
The reason for the error is that HA is trying to work out what {{ 192.168.88.229 }} is — you’ve written it as a template. It’s working its way along it, finding a decimal number 192.168, then getting confused at the next bit, where you ask for .88, which is the same notation as asking for an element of a list:
{{ [3,1,4,1,5,9].2 }} # is 4 (.2 is the third item as we count from 0)
{{ [3,1,4,1,5,9][2] }} # equivalent notation
Numbers don’t have indexable elements, so it throws an error.
Thanks for explanation @tom_l My mistake I was looking for bug in shell command instead to check if my code is correct . I will try when I will be home. Really appreciate help from your both.
It is possible that the HASHVAL you are passing is not the current HASHVAL. Since I have only two (Smartcast and DirecTV), these two basically switch Smartcast to DirecTV and DirecTV to Smartcast.
If you are trying to go from like HDMI-2 to something, it will not work for you. I never was successful in writing a one-liner that gets current HASHVAL and passes that, but someone suggested this (it did not work for me):
From AUTH you mean. This is because you are passing in a fixed AUTH code. I have 5 Vizios so I pass in the AUTH value and hence use {{auth}} as a variable in the service call.
Ahh, I see. Yes, I removed the brackets from the auth and the ip and port. I am trying to pass a fixed set of parameters to a single tv to get it to start up on the correct input.
This should work for my purposes… I can have the TV default start on the home screen and then post this code to it to go where I need it. Even if other people have manually changed it through out the week, I can automate it to be correct for when I run my start up automation.
On a separate note I was looking at your code for the remote and I got some of it up and running, (just the part where I get the sensor working). But then I get lost for building the GUI… honestly I don’t even need a GUI I just want to automate another tv I have to select a file on a usb…is there a way I can use this code you have written, (pasted below) inside an automation to trigger button presses in a specific order to get my tv where I want it after boot up? I would want to post each button press manually after a set delay in the automation I don’t mind writing each line since its just one TV that has the usb file.
vizio_processkey:
url: 'https://{{ ip }}:{{ port }}/key_command/'
method: put
content_type: "application/json"
headers:
AUTH: '{{ auth }}'
payload: '{"KEYLIST": [{"CODESET": {{ codeset | int }},"CODE": {{ code | int }},"ACTION":"KEYPRESS"}]}'
verify_ssl: false
After speaking with the team I am thinking it might just be easier to leave this one TV manual as the content on the flash drive is abundant and it changes sometimes, stuff in different folders, etc. It seems too complicated to automate. Thank you for the willingness to help, and for your time.