I have been going in circles trying to get a basic script working, I must be missing something. I have two input_numbers: one for the volume of the TV and one for a slider to control that volume (i have a dumb TV and a broadlink) the python script takes the two numbers and adjusts the volume to be the same so I can use the slider to adjust the volume on the TV.
here is the automation that calls the script:
alias: TV Volume Down
description: ''
trigger:
- platform: template
value_template: '{{(states.input_number.tv_vol_slider.state | int) < (states.input_number.tv_volume.state | int)}}'
condition: []
action:
- data_template:
slider: '{{ (states.input_number.tv_vol_slider.state | int) }}'
tv: '{{ (states.input_number.tv_volume.state | int) }}'
service: python_script.tv_volume
here is the python I am using:
tv_vol = data.get('tv')
slider_vol = data.get('slider')
vol_dwn = 'JgDMAHI4Dg8OKw4PDg4PDg4PDg4ODw4ODw4ODw4ODg8OKw4PDg4PDg4ODw4ODw4ODg8ODg8rDg4PDg4ODw4ODw4ODw4ODw4rDw0PDg4PDg4OKxANDg8OKw8NDw4ODw8NDyoQDQ8qEAAJiXM4EA0PKg8ODg4PDg4ODw4ODw4ODw4ODg8ODg8OKw8NDw4ODw4ODw4ODg8ODg8ODg8qEA0ODw4ODw4ODg8ODg8ODg8qDw4ODw4ODw4OKw8ODg4PKg8ODg8ODg8ODisQDQ4rDwANBQAAAAAAAAAAAAAAAA=='
vol_up = 'JgAyAXM4Dw4OKxANDg4PDg4ODw4ODw4ODw4ODw4ODg8OKw4PDg4ODw4ODw4ODg8ODg8ODg8qDw4ODw4ODw4ODw4ODg8ODg8ODg8ODg4PDg4PKg8ODg8ODg8ODg8ODg4PDisODw4rDgAJgXM4Dg4PKw4ODg8ODg8ODg8ODg4PDg4PDg4PDg4OKw4PDg8ODg4PDg4PDg4PDQ8ODw4rDg8ODg8ODRAODg4PDg4ODw4PDg4ODw4ODw4OKw4PDg4PDg4PDg4ODw4ODyoPDg4rDwAJgXI4Dw4OKw4PDg4PDg4PDg4PDg4PDg4ODw4ODg8OKw4PDg4ODw4PDg4ODw4ODw4ODw4rDQ8PDg4PDg4ODw4ODw4ODw4ODg8ODg8ODg8OKw4ODw4ODw4ODg8ODg8ODisPDg4rDgANBQAAAAAAAA=='
if (tv_vol > slider_vol):
num_loop = tv_vol - slider_vol
service_data = {'host': '10.0.0.12', 'packet': vol_dwn}
for x in range(num_loop):
hass.services.call('broadlink', 'send', service_data, 'False')
time.sleep(0.5)
hass.states.set('input_number.tv_volume', slider_vol, 'False')
else:
if (tv_vol < slider_vol):
num_loop = slider_vol - tv_vol
service_data = {'host': '10.0.0.12', 'packet': vol_up}
for x in range(num_loop):
hass.services.call('broadlink', 'send', service_data, 'False')
time.sleep(0.5)
hass.states.set('input_number.tv_volume', slider_vol, 'False')
else:
pass
and here is the error I get…
Log Details (ERROR)
Logger: homeassistant.components.python_script.tv_volume.py
Source: components/python_script/__init__.py:205
Integration: Python Scripts (documentation, issues)
First occurred: 2:14:22 PM (1 occurrences)
Last logged: 2:14:22 PM
Error executing script: unsupported operand type(s) for -: 'str' and 'str'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 205, in execute
exec(compiled.code, restricted_globals)
File "tv_volume.py", line 8, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'str'