Get HassOS version through command_line sensor

Hi!

Hass.io 0.105.2 on a Raspberry Pi 4.

I want to retrieve the installed HassOS version (currently 3.9) to be used in automations and in other places.

Running the command ‘hassio hassos info’ at the command prompt through SSH gives

core-ssh:~# hassio hassos info
board: rpi4
boot: B
version: "3.9"
version_cli: "16"
version_cli_latest: "16"
version_latest: "3.9"
core-ssh:~#

which looks very promising as I can see both ‘version’ and ‘version_latest’

To get it as a sensor into hass.io I was hoping to use the command line sensor:
https://www.home-assistant.io/integrations/sensor.command_line/

In my configuration.yaml I added

sensor:
  - platform: command_line
    name: hassos
    command: "hassio hassos info"

but in developer tools > states I find nothing useful after reboot.

Ideas anyone? Thanks!

I think it is to do with the fact that the command line sensor is run in the home assistant docker. Whereas core-ssh isn’t.

1 Like

By that you mean it is not possible to run the command line sensor from withon hass.io?

I’d like to reboot this thread.
I’m trying something similar to @f00dagi.

Running ha info (or ha info --raw-json as I use in my sensor) from SSH docker gives me a bunch of info I’d like to pipe into a sensor to make my update notification to Telegram a bit nicer:

~ $ ha info
arch: armv7
channel: stable
docker: 19.03.12
features:
- reboot
- shutdown
- services
- network
- hostname
- hassos
hassos: "4.16"
homeassistant: 0.117.6
hostname: homeassistant
logging: info
machine: raspberrypi4
operating_system: HassOS 4.16
supervisor: 2020.11.0
supported: true
supported_arch:
- armv7
- armhf
timezone: Europe/Copenhagen

I have a sensor setup similar to the one in the first point, just using json to pick up the desired pieces:

  - platform: command_line
    name: hassoscurrentversion
    command: "hassio info --raw-json"
    value_template: "{{ value_json['data']['hassos'] }}"

It does not provide any output, but putting the output from ha info to a text file and letting the sensor cat it, works as expected.

So - is it not possible to run “ha” from inside the ha-core docker image?

Decided to install the Portainer add-on, entered cli on homeassistant container - and sure enough no “ha” or “hassio” command.
So - is there any way to add the command to the image?

It is in the hassio_cli container. So a command line to access the ha command should be

docker exec -it hassio_cli ha [whatever]

Only problem is that docker is not available from within the homessistant container which executes the command_line sensors.
So it might be reasonable to setup cron to gather the info at an interval and inject it to a file and let a command line sensor “cat” that, but not without setting up ssh access to the host machine which I think is contrary to the HASSOS idea (maybe I’m wrong).
What I’m looking for is a way to get the information that “ha info” provides from within the standard HASSOS setup to be able to include it in automations, matching what is provided by the “version” sensor.

please have a look at the topic below, you can pull a lot more data

Awesome - just what I was looking for!

Hi, were you able to create this sensor?
Can you tell me how to do it? Thanks

Isn’t this what you are looking for?

state_attr('update.home_assistant_operating_system_update', 'installed_version')

1 Like

This was superseded by the new sensors included in HA and add-ons: