I created a new script based on your idea to generate a lot of config, if you log in to Avanza and navigate to an account it lets you generate all your stocks with shares and everything as a long list of sensors. Was actually quite nice to have if/when you sell and buy stocks, to always have your sensors up to date!
Ah, you have to run it through tampermonkey (https://www.tampermonkey.net/). It will install as a ChromeExtension. When installed, go to the tempermonkey icon, click dashboard in the menu, then the + next to installed scripts and paste the code. Hit CTRL-S to save and then browse to avanza. You will see a red icon with a 1 on top of the tampermonkey icon to indicate that there is 1 running script
Getting the following error when running the script.
Mon Aug 26 2019 14:21:53 GMT+0200 (centraleuropeisk sommartid)
Error executing script: âNoneTypeâ object is not subscriptable
Traceback (most recent call last):
File â/usr/src/homeassistant/homeassistant/components/python_script/init.pyâ, line 182, in execute
exec(compiled.code, restricted_globals, local)
File âtelegram_dividend.pyâ, line 9, in
File â/usr/local/lib/python3.7/site-packages/RestrictedPython/Eval.pyâ, line 35, in default_guarded_getitem
return ob[index]
TypeError: âNoneTypeâ object is not subscriptable
So, not getting any output from the script, error message is
Error executing script: 'NoneType' object is not subscriptable
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 194, in execute
exec(compiled.code, restricted_globals, local)
File "telegram_dividend.py", line 9, in <module>
File "/usr/local/lib/python3.7/site-packages/RestrictedPython/Eval.py", line 35, in default_guarded_getitem
return ob[index]
TypeError: 'NoneType' object is not subscriptable
Why is this?
Is it when stocks have the following it does occur.
dividend0_amountPerShare: unknown
EDIT: One stock was still in the notification, but sensor was missing.
BR
If you are using my script above I would guess that attributes = entity.attributes returns None, which would indicate that the entity has no attributes or the entity id is wrong. I would suggest to try and debug the script using logger.info(âŠ)
Hello @claha and thanks for this custom component.
I had a few problems geting this to work as I would, so Iâm just describing my findings for future readers I also have a suggestion at the end of my post.
I have the following config in my configuration.yaml
Hi @ibennani! Happy that you like and use the component
Using monitiored_conditions you can add both an id attribute and name attribute. If you donât specify a name for the sensor it will be named sensor.avanza_1234. Please let me know if this is not enough for your needs and I will have a look to see what could possibly be updated.
Hello again @claha.
Looked at the github readme and Iâd love to have all the sensors named sensor.avanza_stock_ by default. Now when I have this config:
After asking a lot, itâs finally CONTRIBUTION TIME!
Hereâs my MVP/quick-and-dirty example of a script that reads out the stockchange attributes in all the defined stocks and funds into one specific Google Home speaker. This requires that the Google Home has already been setup in your HA installation.
This also requires that the changePercent attribute is enabled, like this:
@ibennani I looked at other components which has a lot of attributes, like Weather, and thoose all seemed to follow the pattern to have a monitored_conditions (the name monitored_conditioms should probably change for this platformâŠ).
Love the script, will definetly try it out. I send myself a telegram message after the stock market closes with a summary of todays changes.