2017-05-31 20:32:36 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform broadlink
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py”, line 155, in _async_setup_platform
entity_platform.schedule_add_entities, discovery_info
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py”, line 135, in setup_platform
device_config.get(CONF_COMMAND_OFF)
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py”, line 161, in init
self._command_on = b64decode(command_on) if command_on else None
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/base64.py”, line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
Broadlink switches are currently working for me. My command_on and command_off fields get turned into switches on my home assistant dashboard (albiet it is a bit messy)
This is my config. I had same problem all i did was add = <- Equals symbol to end of each command on and command off and then the switches would show up in my frontend.
I was organizing my IR buttons into scripts so that they wouldn’t be switches and I realized you might be able to bypass the whole “switches not showing up” thing if you ran scripts using the “send_packet” command example from the broadlink component page.
I wanted to clean up my IR blaster HASS dashboard buttons anyway by making scripts to trigger the switches, since I think it looks nicer. If you want to try that, read on – if not, no worries I just got excited and wanted to post my setup below:
=======================================
Making broadlink switches into grouped scripts:
Code for my switches (re-posted with new variable names):
I made scripts to trigger my switches, so that there’s an “activate” button instead of toggles or on/off buttons. You could just do the send_packet thing here instead.
script:
#These IR scripts are written so that HASS dashboard will display a one-shot "activate" button for these 'dumbfire' IR blasts (instead of a displaying a toggle for a smartdevice, which would falsely imply a known state of on/off for each action)
ac_temp_up:
sequence:
- service: switch.turn_on
entity_id: switch.ac_temp_up
ac_temp_down:
sequence:
- service: switch.turn_on
entity_id: switch.ac_temp_down
ac_fan_speed:
sequence:
- service: switch.turn_on
entity_id: switch.ac_fan_speed
ac_mode:
sequence:
- service: switch.turn_on
entity_id: switch.ac_mode
ac_timer:
sequence:
- service: switch.turn_on
entity_id: switch.ac_timer
livingroom_amp_vol_up:
sequence:
- service: switch.turn_on
entity_id: switch.livingroom_amp_vol_up
livingroom_amp_vol_down:
sequence:
- service: switch.turn_on
entity_id: switch.livingroom_amp_vol_down
livingroom_amp_bass_boost_eq:
sequence:
- service: switch.turn_on
entity_id: switch.livingroom_amp_bass_boost_eq
Bonus round: Customize icons + hide any extra unused switches:
[quote=“robertpe, post:5, topic:18895”]
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/base64.py”, line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding[/quote]
[quote=“aimwarlock, post:9, topic:18895”]
I had same problem all i did was add = … Equals symbol to end of each command on and command off and then the switches would show up in my frontend.[/quote]
I may have gotten carried away. I re-read your post and it sounds like there could be a problem with the formatting of your capture code? Try capturing some new codes and ensure they’re in base64 ? (you already mentioned you found the capture service via: HomeAssistant > Developer Tools > Services > “Domain:” broadlink , “Service:” learn_command_192_168_1_xx , but just making sure you’re using that one).
Another thing it could be: I learned by accident that variables cannot have capital letters in them. Maybe try changing “thing”/“item”/“variable” names, like CONF_COMMAND_OFF, to lowercase.
Hm, I can’t remember, but here’s all my code including groups and views if that helps (see All IR Blaster Code: below). I forgot to post the groups and views code above, so maybe the fact that I’ve grouped them makes HASS do this slider action instead of lightning bolts? It may also be by action of the assumed_state: false setting under each switch’s homeassistant: customize: custom display field.
A note on making single-shot “ACTIVATE” buttons though (I accidentally wrote this paragraph and then realized you probably meant those jelly bean sliders, not the activate buttons, and I also realized I already wrote about this haha, but I’m just gonna post this info anyway since this time I wrote a cleaner post): Since the broadlink creates a switch for every IR command (one command is the “on” switch, another command or the same command can be the “off” side of the switch), I created separate scripts that trigger the “on” of each Broadlink-made switch. It’s redundant code, and cumbersome to implement. I wish the Broadlink component had an easier workaround for this (I know you can just create scripts that fire IR codes, but I like to see all variable collected under the Broadlink component in my YAML, so I still use the switches).
.
Sample code for one-shot buttons that say “ACTIVATE”:
Yes, it was the assumed_state: false that sets the display to the toggle. (thanks, @Bobby_Nobble)
But…
I ran into a situation (that I created another thread about) in which I set all the broadlink entities to assumed_state: false and all but one of them displayed the toggle afterwards. I’m not sure where the assumed_state: true was being set but it was listed in the entity attributes as true. I could force it to false there and the display changed to a toggle but as soon as I restarted HA it went right back to the two buttons again.
Someone suggested I put the assumed_state: false in the customize_glob: section for the desired switches and so far that has seemed to make it stick.
Still not sure why/where it was being set to true when none of the others were, tho.
really like your script and would like to learn more on creating group tab etc,
If you dont mind could you share the complete code? I just need to learn how to do some stuff… very nubie, however I manage to change to button thanks to your detail code.
Hey, I’m glad it helped. I think you’re wondering how to create new tabs for your main HASS dashboard? Those tabs are called “Views”. “Groups” are basically cards on the dashboard. The “group:” area in your configuration.yaml file defines both groups and views.
I remember this being a difficult thing to learn when I was just starting too, since the terminology is so confusing. BRUH Automation’s YouTube channel helped me a lot. I recommend checking out Ben’s video here to get your started https://www.youtube.com/watch?v=EsBtyF5tZQ4&feature=youtu.be&t=8m11s
I’ll also copy-paste part the “group:” part of my configuration.yaml file below along with some images. Please let me know if that doesn’t answer the question though. (I’ve added some devices since I last posted my code, but the above code is also still implemented in my setup).
First of all, I want to thank you for your help. The second is that I have a problem with the power switch, once it is in the ‘on’ state and restart home assistant, it returns to false status. I have tried many things but nothing. Does anything have to do with the recorder? I do not understand the scripts either ac_poweroff and ac_poweron.
As far as I know, HASS does not do well with saving states. It doesn’t like to assume anything. When you restart, it will lose whatever you sent last. I have the same issue with my TV power.
Therein lies the big problem with Broadlink controlled RF devices. Worth replacing anything that really matters what the state is with wifi, direct or via mqtt, controlled devices which will report state and sort themselves out when restarting HA. The ubiquitous Sonoff Basics with Tasmota are probably cheaper than the dumb device you’d be replacing.
Can’t thank you enough for sharing your code, Im just getting started with home assistant and you saved me a whole bunch of time and frustration.
Can you please show the config behind the group.sensor_node_1_card & group.sensor_node_2_card entries? I would like to get the temps in a card rather than the bubbles.
I worked out how to do the sensors in a card but Im having problems getting the switches to show up in there own card, any ideas? The temps show up fine but the switches do not, nor do they appear grouped in the main view.