Issue with Low Battery Alarm in Computed Attributes: Alarm Not Triggering Correctly

Kutta2 months ago

Hi everyone,

I'm having an issue with Computed Attributes and hope someone can help.

I'm trying to set an alarm for low battery using the following expression in Computed Attributes:

  • Attribute: alarm
    Expression: (batteryLevel > 0 && batteryLevel < 10 ? "lowBattery" : null)
    Type: string

The problem is that the alarm triggers every time the battery level is less than 10 but greater than 0.

To fix this, I tried the following two expressions:

  1. Attribute: alarm
    Expression: (batteryLevel < 10) && (battalarmSet == false) ? "lowBattery" : null
    Type: string

  2. Attribute: battalarmSet
    Expression: alarm ? (alarm == "lowBattery" ? true : battalarmSet) : (batteryLevel >= 10 ? false : battalarmSet)
    Type: string

Unfortunately, with the second expression, the alarm doesn't get set at all. Does anyone have a solution or know what I might be doing wrong?

Thanks in advance!

Kutta2 months ago

The value of battalarmSet was not Boolean (true or false) but a String ("true" or "false")—I changed the type of battalarmSet to Boolean, but it's still not working.

Turbovix2 months ago

Hello, I think you are using the wrong attribute, I believe the correct one in your case should be "power" instead of "batteryLevel", since the "batteryLevel" attribute returns a percentage (10%, 32%, 100%)

Kutta2 months ago

Hello Thank you, but the batteryLevel only gives me numbers

Turbovix2 months ago

What is a number to you?

Kutta2 months ago

in this case 0-100

Kutta2 months ago

Screenshot 2024-10-10 132252.jpg

Turbovix2 months ago

Okay, that's correct. And why can't you use the "power" attribute?

Turbovix2 months ago

Another thing you are using as a string, you should use it as a number.

Turbovix2 months ago

Captura de tela de 2024-10-10 08-39-51.png

Anton Tananaev2 months ago

The problem is that the alarm triggers every time the battery level is less than 10 but greater than 0.

Why is that a problem and how your new expressions are supposed to fix it?

Kutta2 months ago

Hi Anton, thanks :

batteryLevel < 10 ? "lowBattery" : null

i test it and response

Anton Tananaev2 months ago

I don't think it answers any of my questions.

Kutta2 months ago

With the new expressions I wanted to achieve that when the alarm was set it would be saved and only reset when the battery level increased again

Anton Tananaev2 months ago

Not sure how you expect it to work. You never check last values, so it will obviously not work.