Template warning: 'float' got invalid input

I have an automation to increase the volume by setting the volume instead of increasing (default increase is way too much for my tv). I drew the configuration from this suggested answer: Media Player Volume Sensitivity - #4 by Burningstone

However, the float errors out:
Template warning: 'float' got invalid input 'None' when rendering template '{{ state_attr('media_player.samsung_tv, 'volume_level') | float + 0.05 }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2022.1

So the state_attr is erroring out and HA is substituting 0, which effectively set’s my volume at a flat float of .05. Any suggestions?

Automation:

alias: increase Volume .05
description: ''
trigger:
  - platform: state
    entity_id: input_button.tv_volume_up
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: >-
        {{ state_attr('media_player.samsung_tv', 'volume_level') | float + 0.05
        }}
    target:
      device_id: e713d6acb5b8c890d90f6676bc4eb408
mode: single

Ok, so the initial automation had the wrong name, so i fixed it to what is posted above. Now, no logs are being generated, but the volume is still being set to .05

Can you see any data in the template editor if you put in the below only without the 0.5?
{{ state_attr('media_player.samsung_tv', 'volume_level') }}


Logger: homeassistant.components.automation.increase_volume_05
Source: components/automation/__init__.py:514 
Integration: Automation (documentation, issues) 
First occurred: 2:35:04 PM (7 occurrences) 
Last logged: 3:47:05 PM

Error while executing automation automation.increase_volume_05: Error rendering data template: Result is not a Dictionary
Error while executing automation automation.increase_volume_05: required key not provided @ data['volume_level']
Error while executing automation automation.increase_volume_05: expected float for dictionary value @ data['volume_level']

Ok thanks and if you go to ‘Developer Tools’ and search for the TV under ‘States’, can you please post what is shown?

Is it that it’s unavailable?

Weird, because when i go to my dashboard, I can control volume with the slider, power the tv off, etc.

It’s available now (re-added in the gui) and the run is still giving this error:

Logger: homeassistant.components.automation.increase_volume_05
Source: components/automation/__init__.py:514
Integration: Automation (documentation, issues)
First occurred: 2:35:04 PM (10 occurrences)
Last logged: 6:36:16 PM

Error while executing automation automation.increase_volume_05: Error rendering data template: Result is not a Dictionary
Error while executing automation automation.increase_volume_05: required key not provided @ data['volume_level']
Error while executing automation automation.increase_volume_05: expected float for dictionary value @ data['volume_level']

Have you had any more success with this? I would suggest for testing purposes to forget the automation for the moment and just work on getting the value to display in the template editor under developer tools. This will help you troubleshoot how the value is displayed and to be sure that you can get the data. I’ve done some testing on my own side and can return data from an attribute in the same way that you are trying.

When you are testing this, is the tv playing media? I’m not sure if the volume level attribute will be populated unless media is playing. Might be worth double checking as this could be a potential cause of the error.

Hi @Toby1 sorry for the suuuuper late response.

Yes, media is playing. I can even get it to set the volume (using float numbers). But never increase volume.