Multiple Sensors / No Sensors From Command Line Sensor

I have this python script that reads electricity power outages in my neighborhood and prints the result in json format. If there is no planned outages, json comes back as empty, but there might be one or more planned work that causes power outage. I use this command line sensor at the moment:

  - platform: command_line
    name: Gediz Elektrik
    scan_interval: 3600
    json_attributes:
      - starts_at
      - ends_at
      - get_reason
      - get_zones
    command: 'python3 external_data/gdzelektrik_outages.py'
    value_template: '{{ value_json.manuel_zone }}'

I also use an “Entities Card” on the front end. If there is no planned outages, it writes “Unknown”, if there is only one outage, it writes the details on the card, but if there is more than one work, it writes “Unknown” again on the card with log error “Unable to parse output as JSON”

What i try to achieve is:

  • If there is no outage (json empty), no card on the frontend
  • If there is only one outage (single json), only one card on the frontend
  • If there is more than one (dictionary), create as much cards as necessary.

How can i achieve this in a most efficient way?

Use the conditional card to display the card.

Simple, you already have the solution.

This is where it becomes difficult. The easiest way would be to create a series of conditional cards displaying each item if it exists. It will appear to be dynamic, but it is not. Also, it would not work if you only configure 5 cards and 6 planned events occur.

If you want it truly dynamic, you’ll need to create a custom card that does this for you. (I.E. learn js, learn css, learn html, and write your own super card)