Now if I just use the basic “sensor” entries in configuration.yaml, i get the state changes ok. And it’s all good. But I’d like to use the “device_class” setting and can’t use that with basic sensor.
I can use the device_class attribute with binary_sensor, but the same text in the configuration file does not work.
I’ve been pulling my hair out trying to get the thing to work as I understand this will help automate icon changes for things like windows/doors.
It failed because this "0" means string zero, not integer zero. By putting the zero between double quotes you have represented it as a string and not a numeric value. Based on your example, the received JSON data contains numeric values.
Assuming 0 represents on, try this template:
value_template: "{{ 'ON' if value_json.Z03 == 0 else 'OFF' }}"
then you probably would have nailed the template on your own.
Yes, you need to delimit 'ON' within that template because without the quotes the Jinja2 template interpreter will handle it as the name of a variable.
Example employing variables:
{% set cat = 'this' %}
{% set hat = 'that' %}
{{ cat if value_json.whatever == 1 else hat }}