Struggling with MQTT availability template

Hi,

I’ve got an MQTT topic (building/rss/servers/+) that determines the availability for a whole lot of other sensors. Its value is JSON encoded, like the example below:

{"hostname": "felix-control", "pid": 1127478, "startdate": "2023-07-24 12:45", "connected": 1692044532.2032273, "state": "active", "timestamp": 1696013940.0314107}

The timestamp parameter in the JSON should not be very old. To test this I have

  1. an MQTT sensor:
- name: RSS server timestamp offset
  state_topic: "building/rss/servers/+"
  value_template: "{{ float(as_timestamp(now()) - value_json.timestamp) }}"
  1. This MQTT binary_sensor:
- name: RSS server timestamp ok
  state_topic: "building/rss/servers/+"
  value_template: "{{ 'ON' if float(as_timestamp(now()) - value_json.timestamp) < 5 else 'OFF' }}"

And this gives values of 1) “about 0.05 seconds” and 2) “on

Now I try to use this for the availability of another topic. And that doesn’t work. That sensor is always unavailable.

- name: RSS Alarm FELIX
  state_topic: "building/rss/AlarmCondition/RSS/Alarm/FELIX"
  availability:
    - topic: "building/rss/servers/+"
      value_template: "{{ 'online' if float(as_timestamp(now()) - value_json.timestamp) < 5 else 'offline' }}"  

And I don’t understand why it’s always unavailable. It’s even unavailable if I change the last line to value_template: "online" so it should always return the string “online” to compare to the default setting of payload_available, which is also “online”.

In the template editor:

{{ states('sensor.rss_server_timestamp_offset') }}
{{ states('binary_sensor.rss_server_timestamp_ok') }}
{{ states('sensor.rss_alarm_felix') }}

gives

0.04767058372497559
on
unknown

What am I doing wrong?

Edit: it is relevant to add that the actual topic building/rss/AlarmCondition/RSS/Alarm/FELIX is available and contains the correct data. If I remove the availability section, this sensor behaves normally, is available and has valid data.