POST/PUT NULL Value for Item Using REST API

Tags: #<Tag:0x00007faee095fda8> #<Tag:0x00007faee095fc68> #<Tag:0x00007faee095fb00>

Geetings fellow OpenHAB’ers!

I am interested in setting an Item to NULL using the REST API but it does not look like this is an option. I wanted to confirm my findings before I make larger changes.

The MCU backstory is that I was using the HTTP Binding and there were a few things that I didn’t like about that approach, so I instead switched to using a bash script that fetches the content that I need using curl, then I massage the data with jq, and POST it to the OpenHAB REST API. I have several rules that I’ve written checking for NULL values for Items and act accordingly. I could certainly rewrite the rules to handle different values to align with my changes. It’s preferable for me to set NULL values for Items using the REST API if possible. In addition, I’d prefer NULL for historical metrics of said Items.

To be clear, I don’t want to set a string value of “null”, I want NULL. Some of these Items are Number types and I can’t set them to “null”.

The help is appreciated, as always. Thanks!

In openHAB, NULL carries the meaning of “not yet initialized”.
Constructively setting a state to NULL would be a contradiction in terms.
If it is not already NULL, it has been initialized by something.

Perhaps the UNDEF state is more appropriate.

Thanks for the information.

How does one POST an UNDEF value for an Item using the REST API?

Same as you would any other appropriate state value for any Item type.
You cannot send a command UNDEF, that makes no sense.

Now that you mention it - there may be a limitation here on String type Items only. Over REST, OH cannot distinguish UNDEF type from “UNDEF” string, everything gets sent as strings after all. I believe a string Item will get set to “UNDEF” content instead of true UNDEF state.
Rules and bindings can accomplish true UNDEF updates of String Items.

OK so it looks like I have to rewrite my rules to not use NULL. Thanks for the information. At least I have a definitive answer.