How to set a state attribute to null in a script

I have upgraded a Max! heating system in two different locations and since the locations had acquired a few other IoT-devices, then I decided to try and make a central IoT control point based on Home Assistant, but I have run into an issue with some of the IoT items.

In one of the locations its 2 different models of Air-toAir heat pumps.
They have a few state values that can be set, but would otherwise be null if not set, like max and min heat settings on the thermostat.
If I pull those values from HA and the min and max values are not set, IE. they are null, then I get 30 degress celsius as max and 5 as min from one of the devices and some other values from the other, since they are not same model.
If I set the values then I get the values I have set, but I can not set these values back to null again from HA and have the devices report their factory values.
Funny enough I can easily change the values in HA and even set min and max to 0 and 100 and get those reported back, even though I can set the target temperature to anyway.
Whenever I have set the values in HA, then I have to startup the program that came with the devices and reset the values to get back to factory setting.

In the other location I have central heating and I invested Homematic IP devices, but I have a similar problem.
The thermostats have a Boost mode, then move the thermostat valve to open for a set amount of time when triggered and then return to the previous setting afterwards.

When I look in the developer tool I see these state attributes:
hvac_modes: auto, heat, off
min_temp: 4.5
max_temp: 30.5
target_temp_step: 0.5
preset_modes: boost
current_temperature: 21.7
temperature: 20
preset_mode: null
id: 00201A49A56339
interface: ip
battery: High
rssi_device: -59
valve: 4
level: 0
mode: null
voltage: 3
friendly_name: Office Thermostat
supported_features: 17

I have made a template on the device to report the preset mode with this:

sensor thermostat_sensor:
  - platform: template
    sensors:
       thermostat_boost:
            friendly_name: "Thermostat Boost"
            unique_id: "thermostatboost"
            value_template: >-
                {% if (state_attr('climate.thermostat', 'preset_mode') == 'boost') %}
                    On
                {% elif (state_attr('climate.thermostat', 'preset_mode') == None) %}
                    Off
                {% else %}
                    Unknown
                {% endif %}

Whenever I physically activate and deactivate the Boost I get changes on the sensor and it reports On or Off and never Unknown, so it must be able to read the null value.

I have then made a simple script to toogle the Boost on and off.

service: climate.set_preset_mode
entity_id: climate.officethermostat
data:
  preset_mode: |
    {% if (states('sensor.office_thermostat_boost')=='Off') %}
      boost
    {% else %}
      None
    {% endif %}

I can with the script turn the Boost mode on, but I can not turn it off again by setting the value to null.
I had hoped I could make another preset mode on the devices that just lasted 1 second and switch to them instead, but I have not had any luck in doing so yet.
So how do I set a state attribute to null?

Yeah, you’re limited by what you can do here. But what you can do is update your template

thermostat_boost:
            friendly_name: "Thermostat Boost"
            unique_id: "thermostatboost"
            value_template: >
              {% set mode = state_attr('climate.thermostat', 'preset_mode') %}
              {{ 'On' if mode != None and 'boost' in mode else 'Off' }}

This will be state ‘off’ if preset_mode is null, or if it’s not null and says anything other that ‘boost’. So when you set it to the string “None”, it will still be in the off state.

The only way to set that value to null is to either modify the code of the integration, or send a RESTFul API query to the sensor state directly.

My sensor template is working.
Its my script to actually control the device I have issues with.

But thanks for the input.

set it to none, case sensative.

Sorry, I should have mentioned that I have tried different words, like NONE, None, none, NULL, Null, null, NIL, Nil, nil, OFF, Off, off.
I have also tried to sent the words without quotation marks and with single and double.

I have made a second script with no conditional code. It just send the value and nothing else, so I can be sure that it is not my code that does anything wrong.

the code only accepts none.

You may have to set the hvac mode if none isn’t doing anything.

Jocnnor actually solved the problem with the RESTful comment and the Homematic setup.
My debmatic installation does not have a RESTful option, but I found an addon called XML-API that makes it possible to send actions over HTTP-links.
I got the link that works now, so just need to figure out how to implement it in HA, but that should not be hard.

I will have to see what is possible with the Air-to-Air pumps on the other location, but I am optimistic. :slight_smile:

Thanks for the help. I consider this one solved now.