Shell command - UndefinedError: float object has no element 88

Hi,
i am running script to run onkyo net and tuneIN. When i am trying to run it i am geting error like mentioned bellow.

In configuration yaml i have entries about onkyo and shell command

media_player:
  - platform: onkyo
    host: 192.168.88.229
    name: receiver
    sources:
      pc: "HTPC"
shell_command:
  onkyo_command: onkyo --host {{ 192.168.88.229 }} {{ cmd }}

Script which i want to run is

alias: Onkyo
sequence:
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: PWR01
  - wait_template: "{{ not is_state('media_player.receiver', 'off') }}"
    timeout: "00:00:10"
    continue_on_timeout: false
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: SLI2B
  - delay: 1
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: NSV0E0
  - delay: 1
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: NTCSELECT
  - delay: 1
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: NLSI00001
  - delay: 1
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: NLSI00017
  - delay: 1
  - service: shell_command.onkyo_command
    data:
      ip: 192.168.88.229
      cmd: NTCSELECT
mode: single

Error log:

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

Quote your single line templates.

onkyo_command: "onkyo --host {{ ip }} {{ cmd }}"

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.

Sorry guys bit of a novice and not quite sure what you are saying. Could I get some help with this one? I am running into the same issue:

I have blocked out some of the auth code with * for security purposes

shell_command:
  vizio_directv: >
    curl -k -H "Content-Type: application/json" -H "AUTH: {{Zs**k9h8**}}" -X PUT -d '{"REQUEST": "MODIFY","VALUE": "hdmi1","HASHVAL": 2023834057}' https://{{10.20.22.130}}:{{7345}}/menu_native/dynamic/tv_settings/devices/current_input 

Why have you put the auth code, IP and port in brackets?!

I was working with a snippet of code from this post: https://community.home-assistant.io/t/vizio-tv-integration/372376/49

Well here is what I call now:

vizio_directv: >
    curl -k -H "Content-Type: application/json" -H "AUTH: {{auth}}" -X PUT -d '{"REQUEST": "MODIFY","VALUE": "hdmi1","HASHVAL": 2023834057}' https://{{ip}}:{{port}}/menu_native/dynamic/tv_settings/devices/current_input
vizio_smartcast: >
    curl -k -H "Content-Type: application/json" -H "AUTH: {{auth}}" -X PUT -d '{"REQUEST": "MODIFY","VALUE": "cast","HASHVAL": 2129379411}' https://{{ip}}:{{port}}/menu_native/dynamic/tv_settings/devices/current_input

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):

vizio_source_select: >
    hashval=$( curl -s -k -H "Content-Type: application/json" -H "AUTH: {{auth}}" -X GET https://{{ip}}:{{port}}/menu_native/dynamic/tv_settings/devices/current_input | jq --raw-output ".ITEMS[0].HASHVAL" ); curl -k -H "Content-Type: application/json" -H "AUTH: {{auth}}" -X PUT -d '{"REQUEST": "MODIFY","VALUE": "{{source}}","HASHVAL": $hashval}" https://{{ip}}:{{port}}/menu_native/dynamic/tv_settings/devices/current_input

This should run curl and parse out the current hashval and then use a string for {{source}} to set the new input in another curl call.

1 Like

Removing the brackets worked to switch from the vizio tv home screen to hdmi1

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.

shell_command:
  vizio_directv: >
    curl -k -H "Content-Type: application/json" -H "AUTH: Zs6**9h8**" -X PUT -d '{"REQUEST": "MODIFY","VALUE": "hdmi3","HASHVAL": 2023834057}' https://10.20.22.130:7345/menu_native/dynamic/tv_settings/devices/current_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

Well yes you could but what is the state you want it in? Perhaps there is a single command that can get you there.

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.