Reading local json attribute issue

I’m trying to read an attribute from a local json file to retrieve the version installed of a component.
This is the content of version.json and it’s located on: /home/homeassistant/.homeassistant/www/custom_ui/version.json

{
    "dark-sky-weather-card": {
      "updated_at": "2019-01-23",
      "version": "0.8.2",
      "remote_location": "https://raw.githubusercontent.com/iammexx/home-assistant-config/master/ui/darksky/dark-sky-weather-card.js",
      "visit_repo": "https://github.com/iammexx/home-assistant-config/tree/master/ui/darksky",
      "changelog": "https://github.com/iammexx/home-assistant-config/blob/master/ui/darksky/changelog.md"
    }
}

So i’ve created a sensor like:

  - platform: file
    file_path: /home/homeassistant/.homeassistant/www/custom_ui/version.json
    name: customdarksky_current_version
    value_template: "{{ value_json['dark-sky-weather-card'].version }}"

But for this sensor I get always UNKNOWN value instead “0.8.2” expected.

No error from HA log. I don’t know why.

Try {{ value_json['dark-sky-weather-card']['version'] }}

Why not use Custom Updater with the Tracker Card? It reads directly from the .json on github and will also read what version you have installed, and even give you an option to update the component/card from your Lovelace UI.

Cause some components, like zigbee2mqtt, doesn’t support it… So i don’t want to mix methods to get current version…

Fair enough. I use it for all the custom cards that work with it, I have a lot, so it’s easier to use that and have them all in that nice neat card. I also have a few custom sensors for things like pi-hole, zigbee2mqtt, and HA itself.

Not sure if this is of any interest, but this is what I use to track Zigbee2mqtt. I have the same for pi-hole. Haven’t got around to using this to track HA yet.

The command line sensor gets the currently installed version, the rest sensor gets the latest version from GitHub, and the template sensor combines the two and tells me the current version, but if a new version is available, it tells me “Update Available”.

  - platform: command_line
    name: zigbee2mqtt_installed_version
    command: 'cat /opt/zigbee2mqtt/package.json'
    value_template: '{{ value_json.version }}'
    scan_interval: 3600

  - platform: rest
    name: zigbee2mqtt_github_version
    resource: 'https://api.github.com/repos/Koenkk/zigbee2mqtt/releases/latest'
    headers:
      accept: application/vnd.github.v3+json
      content-type: application/json
      user-agent: home-assistant/rest-sensor
      Authorization: !secret github_header_token
    value_template: >-
      {{ value_json.tag_name }}
    scan_interval: 360

  - platform: template
    sensors:
      zigbee2mqtt_version:
        entity_id: 
          - sensor.zigbee2mqtt_github_version
          - sensor.zigbee2mqtt_installed_version
        friendly_name: Version
        value_template: "{%- if states.sensor.zigbee2mqtt_installed_version.state == states.sensor.zigbee2mqtt_github_version.state -%}{{states.sensor.zigbee2mqtt_installed_version.state}} {% else %}Update Available {{states.sensor.zigbee2mqtt_github_version.state}} {% endif%}"
        icon_template: >-
          {% if states.sensor.zigbee_installed_version.state == states.sensor.zigbee_github_version.state %}
            mdi:checkbox-marked
          {% else %}
            mdi:checkbox-blank-outline
          {% endif %}

Thank you! With your example i got my example working!

1 Like

Hi, a question: is it possible to add your example for zigbee2mqtt inside custom tracker?

i’ve copied your code and try to add in ui-lovelace.yaml but i get problem:

- type: custom:tracker-card
    title: Aggiornamenti
    trackers:
      - sensor.custom_card_tracker
      - sensor.custom_component_tracker
      - sensor.zigbee2mqtt_version  //  <- this line broke all my frontend page

It wont work. It doesn’t use the required json file needed for the tracker card. Also, remember that Zigbee2mqtt is separate from Home Assistant. Home Assistant can connect to Zigbee2mqtt via MQTT, so no amount of anything will get this to work with the tracker card.

1 Like

OK. last question ( I hope): can i track HA version with this component? Actually I don’t find anything about it. Actually i’m still using old method like:

- platform: rest
  resource: https://s3.amazonaws.com/hassio-version/stable.json
  name: Hassio Version
  value_template: "{{ value_json.homeassistant.default }}"
  scan_interval: 3600

- platform: version
  name: Installed Version

There are 2 methods. One is to read the file in your config directory. The file is .HA_VERSION, or there is a command line. By the looks of it you are using HASS.io which is a little different to what I use. I have Home Assistant in a virtual environment on running under Raspbian.

This is what I use to get the version.

  - platform: command_line
    name: Installed Version
    command: /srv/homeassistant/bin/hass --version

More information can be found on the Version Sensor. At the bottom there are some alternative methods. I think the last 2 might work for you but have a play with them and see what works with HASS.io.

No i’m not using hassio. I’m using rassbian with H A installed