How to use/debug value_template?

I have the configuration for the following sensor (a SimpliSafe-Gen3 sensor via rtl433):

{
  "state_topic": "rtl_433/+/devices/SimpliSafe-Gen3/31729740",
  "name": "Front Door (SimpliSafe local)",
  "device_class": "door",
  "force_update": "true",
  "expire_after": "43200",
  "payload_on": "0",
  "payload_off": "1",
  "value_template": "{{ (value_json.ctr % 2) }}",
  "unique_id": "rtl433_simplisafe_31729740",
  "object_id": "rtl433_simplisafe_31729740"
}

The purpose is to show this as Open when “ctr” under the state topic is even and Closed when it’s odd.
This is definitely the case and I can see the correct data via MQTT Explorer.

However, HA shows this entity as “Unavailable”. I have no clue why.
There is no log entry so I don’t know how to debug.

I solved it! I changed the state topic to include “ctr” and then I used “{{ int(value) % 2 }}” as a template. The conversion to int was important.

1 Like