Setting sensor values if they are out of defined bounds

Hi,

I am new to Home Assistant, so please forgive me, if my question is stupid.
I have integrated my curtains with localtuya and it works, but there is a problem.

Let’s suppose I close my Curtains in the evening with my HA App.
The next morning my wife opens the curtains with the hardware switch, which is also installed in our house. Now Home Assistant thinks, my curtains are still closed. If I want to close the curtains it is not possible, because HA thinks they are already closed. This is why my curtains sometimes doesn’t close in the evening, which is pretty much annoying.

I already found a way to manually change the sensor values, I found them under “Entwicklerwerkzeuge” → “Zustände” (I would translate it to “Developer Tools” → “state”, but I don’t know exactly what the english version says). There I can set the curtain sensor to 50 for example.

Now I want to automate this.

I need something like:

if( sensor.value < 10 || sensor.value > 90){
    sensor.value = 50;
}

Does anyone know, where and how to archive this?

How were your curtains added to home assistant?

Why do they not provide state feedback?

Changing the value in Developer Tools → States is not permanent and is intended for debugging only.

The curtains were added via localtuya (HACS). They are just some switches, who doesn’t provide any state feedback.

That’s why, I use “timed” as my positioning mode.

I know, that changing the value in Developer Tools is for debugging, that’s why I am looking for a way to use it permanently. Best would be, if the state would be a read only variable an fixed to some value which is not 0 and not 100.

I use filters for this. I’d start by using the outlier filter.

@PeteRage: Thank you for your awnser.

I tried and added the following code:

sensor:
  - platform: filter
    name: "Terrassentür Rolladen"
    entity_id: cover.terrasse
    filters:
      - filter: range
        upper_bound: 51
        lower_bound: 49

But unfortunately I got the following Message while trying restart HomeAssistant (my translation in brackets):

Fehler beim Neustart von Home Assistant [Error while restarting HomeAssistant]
The system cannot restart because the configuration is not valid: Invalid config for [sensor.filter]: Entity ID ‘cover.terrasse’ does not belong to domain ‘sensor’ for dictionary value @ data[‘entity_id’]. Got ‘cover.terrasse’. (See ?,line ?).

Can you please explain, what I have done wrong?

That seems like a limitation of the filter.

You’ll need to add an intermediate sensor template. Something like this.

sensor:
  - platform: template
    sensors:
      terrasse:
        value_template: >-
          {{ states('cover.terrase') }}
  - platform: filter
    name: "Terrassentür Rolladen"
    entity_id: sensor.terrasse
    filters:
      - filter: range
        upper_bound: 51
        lower_bound: 49

Thanks PeteRage,

but unfortunately it does not work.

I looked into the logs:

Logger: homeassistant.components.hassio
Source: components/hassio/init.py:517
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: 19:08:06 (1 occurrences)
Last logged: 19:08:06

The system cannot restart because the configuration is not valid: Invalid config for [sensor.filter]: Entity ID ‘cover.terrasse’ does not belong to domain ‘sensor’ for dictionary value @ data[‘entity_id’]. Got ‘cover.terrasse’. (See ?, line ?).

And this Error occured in the logs as well:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/hassio/init.py:528
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 19:08:06 (1 occurrences)
Last logged: 19:08:06

[547312353392] The system cannot restart because the configuration is not valid: Invalid config for [sensor.filter]: Entity ID ‘cover.terrasse’ does not belong to domain ‘sensor’ for dictionary value @ data[‘entity_id’]. Got ‘cover.terrasse’. (See ?, line ?).
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 199, in handle_call_service
await hass.services.async_call(
File “/usr/src/homeassistant/homeassistant/core.py”, line 1808, in async_call
task.result()
File “/usr/src/homeassistant/homeassistant/core.py”, line 1845, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File “/usr/src/homeassistant/homeassistant/components/hassio/init.py”, line 528, in async_handle_core_service
raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Invalid config for [sensor.filter]: Entity ID ‘cover.terrasse’ does not belong to domain ‘sensor’ for dictionary value @ data[‘entity_id’]. Got ‘cover.terrasse’. (See ?, line ?).

The error says you still have cover in the filter. In my example this is now a sensor.