Templating knowledge needed to exclude elements of an array (CL sensor, curl)

I came up with a working solution meanwhile (note: created with AI assistance, even it took almost a dozen attempts to fine tune and remove all the errors). Here’s the command part, just in case anyone ever tries to achieve the same:

      command: >
        curl -s http://xxx.xxx.xxx.xxx:40850/api/XXXXXXXXXX/sensors | 
        jq -r '
        def ignore_list: ["device name A", "device name B", "device name C"];
        def is_recent: .lastseen > (now - 14460 | strftime("%Y-%m-%dT%H:%M:%S"));
        {
          "devices": [.[] | select(.manufacturername == "LUMI" and (is_recent | not) and (.name as $n | ignore_list | index($n) | not))] | map(.name) | sort | unique,
          "total": [.[] | select(.manufacturername == "LUMI" and (is_recent | not) and (.name as $n | ignore_list | index($n) | not))] | map(.name) | sort | unique | length
        }'

Unfortunately (my initial ultimate goal) it is still not possible to use a ignore group (so another “group.ignored_devices”. That’s for the version 3 then:

  • It would only be able to contain entities, while the string comparison in the jq part (rather: the API output) has device names, so there needs to be an extra mile doing “sensor.device_a_temperature → get device name → compare that one”.
  • That was one too much even for the AI.
  • Therefore for now I maintain my list of ignored devices in the ignore_list array.
  • Only actual downside of this: I need to reload the command line sensor after making changes to that ignore_list every time. A group would be much more convenient because rather “dynamic” here.