Rest Binary sensor with non-default state


I am new to HA and have just began including some sensors using the REST sensor/binary sensor. The first effort went pretty well and I have successfully integrated a temperature sensor. I am, however, having some issues with a door sensor due to the state being reported as “present” and “not_present” instead of the “true/false” etc. Is there any way I can make this work? The state is now constantly reported as “closed”.


I’ve never used a REST sensor, but I’m guessing you could use value_template with the binary REST sensor to define the template for the value. Something like

value_template: "{{ value_json == 'present' }}"

Thanks, I will try this.

I am currently using the template to extract the values:

value_template: '{{ value_json["reported"]["temperature"]["value"] }}'

Would the following line then work?:

value_template: '{{ value_json["reported"]["temperature"]["value"] == 'present' }}'

How does HA then enterprets the not_present value?

That should work. It’s implied that when the value is not_present the sensor will be off because the template only evaluates to true when the value is equal to present. For a binary template sensor, true means on and false means off.

If you add device_class: door as well, you’ll end up with

present -> true -> on -> open
not_present -> false -> off -> closed

If you need it switched around so that present means closed, just replace present with not_present in the value_template or change == to != and leave present.

1 Like

Just FYI, if you use single quotes around the template, change present to be use double quotes or it won’t parse right.

1 Like

Thanks alot for the help and syntax tip! It worked like a charm!

Just a general question also: Even though the sensor reports open for a short while (a few seconds, while opening a door), home assistant does not seem to record this. Is there any way of controlling how often or how you subscribe to these events?

I think scan_interval is probably what you want. I don’t know for sure if it works with the rest sensors but that’s the only thing I can think to try.