How to add and update a custom binary sensor?

I think they want to use UP and DOWN in automations as well… for reasons? I’m not entirely sure, tbh.

If the screen is moving( power usage ) for 20 sec and the status is UP, then the status must be changed to DOWN

I do this now in an automation with at text helper, see above

If there is a easier way , im all ears

But how/where should i implement the code from Bill, unclear for me

{{ iif(states(‘sensor.screen’) == ‘on’, ‘UP’, ‘DOWN’) }}

Ah, ok. I see the confusion now. That template code would be in lovelace (displaying in a card). You could also use it in a template helper as well. Either way, it’s just for display purposes to change on and off to up and down.

In your automation, you don’t need UP or DOWN, you just need to check for on and off. Home Assistant uses on and off for pretty much everything.

So i can add this code in a card

{{ iif(states(‘sensor.screen’) == ‘on’, ‘UP’, ‘DOWN’) }}

and that it will display UP or DOWN ?
But sensor.screen , must be some how be ON or OFF , i think ?
i still do not know how to set it ? Because screen is up or down after after 20sec of power usage was high. (after that to power usage is low )
So it looks to me i have to set a value at the automation .

That’s why I suggested using a trend helper. Basically, the trend sensor can monitor the Shelly power. If it’s above a value (I don’t remember what value you used earlier, sorry), then it’s on, meaning the screen is moving. If it’s below that value, it’s off. This would be for your UP/DOWN sensor (name it something like screen_movement_sensor). When the screen is going up, the trend sensor will notice that the power has gone up and trigger on that. You should also create a toggle helper called something like screen_up and set it to on when the screen has gone up and then off when the screen is down.

This is how I would do it (after I created the trend and toggle helpers):

description: Track Screen Position
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.screen_movement_sensor
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 20
condition: []
action:
  - if:
      - condition: state
        entity_id: input_boolean.screen_up
        state: "off"
    then:
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.screen_up
    else:
      - service: input_boolean.turn_off
        target:
          entity_id:
            - input_boolean.screen_up

Then, for your card to display properly (I’m a big fan of using iif, but you can write it other ways):

{{ iif(states('input_boolean.screen_up') == 'on', 'UP', 'DOWN') }}

One thing to note; You said that when the screen is going up, then it uses power for 20 seconds, is that true for going down as well? You might need to adjust the for clause in the trigger if the timing is different for up and down (or create 2 automations perhaps). You can also just use input_boolean.toggle as well, but I like explicitly setting input_boolean state.

Thx for helping me

i still struggling with the trend

image

it is always “Unknown”

i linked it to the correct shelly POWER sensor

what should be the attrribute of this entity?

What do you want from the binary sensor, why exactly do you want it?

I see you are trying to do something with Somfy blinds. Are the IO motors or RTS? There may be whole other ways to do what you want to accomplish. If only we knew what you want, not how you think you should do it.

For instance, if you have Somfy IO motors, for very little money you can build this, no soldering required. Very clear instructions. With it you can both control the blinds, AND know what positions they have, even if you control them with your own remote:

1 Like

The attribute should just be state.

Leave this blank when creating the sensor (or set it to state class).

Dude… I am SO sorry! I recommended Trend when I meant the Threshold helper. Create a Threshold helper. I am really sorry about that. I was working with trend sensors the past few days and it just sort of came out in my typing… :rage:

aah ok m no probleme

I’m glad I’m being helped

1 Like

still an issue with this code?

ok i added the treshold helper an toggle helper ( same names you said ) it is working
But still

it usses 75W for about 20sec to go up or down. So there is no difference in UP and DOWN
when it is not running , it uses 3W

True. But we’re getting closer :slight_smile:

So, in your threshold sensor, have your upper limit be something like 80 and your lower limit be 5. That way, anything between 5w and 80w will be the sensor on.

Looks like you didn’t choose a card type? Try using the Markdown card to start.

ooh ok… it will be then

image

but is it possible to add it like this ??
image

Now you’re just getting fancy :smiley:

There’s two ways I can think of to do it. The first way would be to use something like GitHub - thomasloven/lovelace-template-entity-row: 🔹 Display whatever you want in an entities card row.. The second way would be to create a template helper and use that in your entities card row.

Personally, I’d go with option #1 (the template entity row). I use it A LOT in my setup.

but how can i set the template helper set to UP or DOWN

Just use a regular template sensor (don’t choose binary sensor). Leave UOM, Device Class and State Class all blank.

1 Like

it is working and have a nice layout

a million thanks

1 Like

Ha! Awesome! Happy to help.