Hello there,
I write my Home Assistant configuration with IntelliJ IDEA (I know, probably overkill, but I can’t really get away from it lol) and I’ve always been frustrated by the absence of code insight features. After some time debating with myself about the time that would be wasted effort that would be required for developing such a tool, I decided to experiment with an IntelliJ plugin:
Beware that at the moment this is (awfully) alpha quality software, however I’ve been using it for a few days with no issues - except maybe for some performance issues - not really big-deal issues, but I’ll have to work on those.
In order for the plugin to work, you’ll need to add the Home Assistant facet to the module containing the yaml files. The facet requires the URL to the instance and an access token to retrieve the list of actions and entities from your Home Assistant instance.
In PyCharm, a per-project settings section is available in Settings > Tools > Home Assistant.
If you want to use the latest master, you’ll have to build it manually - fortunately JetBrains made that very easy:
# beware of the submodules!! Use 'git clone --recursive'
./gradlew buildPlugin
You will find a zip file in build/distributions that you can install in IntelliJ using the “Install Plugin from Disk” function.
As I said, this is alpha quality software at this time - also this is my first IntelliJ plugin and I’m a bit rusty on Kotlin - please be kind and give feedback if you want this plugin to improve
Im building this and will test it, thanks for your work!
Edit: Is there any chance to also make it available for PyCharm?See edit 3
Edit 2: For anyone else building and installing. When you install from .zip file, there is no modal or pop-up that says it is importing/installing the plugin. Select the .zip file, and when it brings you back to the INSTALLED plugins modal, click “Apply” or “OK” and it will install the plugin. You can confirm this by looking in your installed plugins:
Edit 3:
When I use it in IDEA, I can get it to auto complete actions/services and !secrets, but I cant seem to get it to auto complete entities.
For pycharm
The requirement to add it as a facet to a module is IDEA specific due to the project settings not having a module/facet editor in pycharm. However, I can install the plugin into pycharm and add the facet to the module by editing the pycharm idea project .iml file and adding the facet and hass generated config from IDEA. The issue then becomes, it isnt properly looking up actions and isnt looking entities up at all. Looking up !secrets works though, so the plugin is somewhat working on pycharm by forcing the facet configuration.
Here is a screenshot of pycharm looking up an action:
Wow I didn’t know Pycharm didn’t support modules. I’ll have to use project settings for that one I guess.
Actually there is no entity completion yet, just “go to reference” (ctrl+click) will open a locally-cached JSON file downloaded from Home Assistant with some information about entities. Actions do have completion though, when you write something in an “action” or “service” dict key.
Entity completion is here! Although I had to add another cache for that… I feel like I’m abusing caches but it’s a lot of stuff to handle and mix (e.g. combining local stuff in the yaml files with remote stuff from HA so that you can reference the local stuff first and then go to the remote stuff if no local definition was found).
Awesome! I can confirm that entity completion is working on my end in IDEA. I can also confirm that the plugin works correctly in pycharm, just need to configure the URL and token in Settings > Tools > Home Assistant.
Just a couple suggestions, idk if they’re possible:
friendly_name
When you ctrl+click the entity name, it brings you to that json states file and shows some attrs, like friendly_name. Is it possible to add additional context like the friendly_name in parenthesis beside the entity name in the completion list or a hover over or similar popup to the entity autocompletion list that would show the friendly name? It would make it much easier to work with entities as some integrations name them like light.<ZIGBEE ADDRESS> (light.0xahg58989287hdfiur876534) which requires looking up the entity in developer tools to see what it actually is.
Support for entity completion in templating
Is it possible to add entity completion support to value_template and similar keys? From my basic thought process, this seems like it would be hard to do, because other fields can support templating and they aren’t standardized. There is the option of triggering on {{ }} and then trying to parse the actual jinja command like states() or state_attr().
script:
google_ai_front_door_notification:
alias: Camera - Front Door - Snapshot, AI & Notification
sequence:
# ALL of the variable key values are templatable
- variables:
trig_ts: '{{ now().strftime(''%Y%m%d-%H%M%S'') }}'
eid: '{% set event_id = mqtt_payload | regex_findall(''event start: (\\d+)'')
| first %} {{event_id}}'
ext_url: https://ha.example.com
- action: camera.snapshot
metadata: { }
data:
filename: /config/www/snapshots/front-door_{{trig_ts}}_snapshot1.jpg
target:
entity_id: camera.front_door
enabled: true
tts_save_ecobee_volume:
alias: Save Current Volume for Ecobee TTS
sequence:
- action: var.set
data:
entity_id: var.ecobee_tts_volume
# Ability to complete entities would be nice in here.
value_template: '{{ state_attr(''media_player.tyler_s_ecobee_smartthermostat_with_voice_control'',
''volume_level'') }}'
Ability to reload config, restart HASS, etc.
Like the VSCode plugin has, commands to reboot host, restart HASS, reload ALL config, check config, reload certain part of hass like automations/scenes/etc.
That would have been my next step: documentation hints - after I stabilize (and publish) the plugin.
I thought about that as well, and that is going to be hard, because as you said I would need to juggle through jinja code - although IntelliJ already can parse (and model) jinja templates, so that will help a bit. We’ll see how it goes.
Good idea. I will add commands that invoke Home Assistant APIs.
I implemented a project settings section (it will be available in PyCharm only for now, I need to check which IDEs support facet and which ones don’t) that will be used instead of facet settings in Pycharm. Beware that the settings you created manually in the .iml file will be ignored and you’ll have to set them again in Settings > Tools > Home Assistant.
I need to stop adding features now and start stabilizing it