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

Kuttaa year 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!

Kuttaa year 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.

Turbovixa year 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%)

Kuttaa year ago

Hello Thank you, but the batteryLevel only gives me numbers

Turbovixa year ago

What is a number to you?

Kuttaa year ago

in this case 0-100

Kuttaa year ago

Screenshot 2024-10-10 132252.jpg

Turbovixa year ago

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

Turbovixa year ago

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

Turbovixa year ago

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

Anton Tananaeva year 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?

Kuttaa year ago

Hi Anton, thanks :

batteryLevel < 10 ? "lowBattery" : null

i test it and response

Anton Tananaeva year ago

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

Kuttaa year 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 Tananaeva year ago

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