PimDoos / ha-sessy-examples

Example automations for using Sessy with Home Assistant
6 stars 3 forks source link

Could you explain this part of the script? #6

Closed npostman closed 9 months ago

npostman commented 9 months ago

https://github.com/PimDoos/ha-sessy-examples/blob/1369bc557be70edbd6d0f4bcf87a17f56d592d52/blueprints/script/sessy/sessy-full-charge.yaml#L137-L141

Hey Pim,

I used this part in a little bit altered script, but when both of my Sessys are full, this trigger does not fire, and I try to find out why. The script stops because of the timeout value, not because both states are 'battery_full'.

Can you briefly explain what you/the script does here?

Thanks in advance, Niels

PimDoos commented 9 months ago

The way this is intended to work, line by line:

  1. Build an array containing the state of each battery
  2. Check if the first entry in the array is 'battery_full'
  3. Check if all entries in the array are equal (which must mean all entries are 'battery_full'

This should then fire a template trigger, causing the wait_for_trigger operation to continue. To be honest: I personally don't use this script that often, so while it should work, I'm not quite sure whether it always will work.

npostman commented 9 months ago

Thanks for the explanation.. So both if's (2 and 3) have to be true in order to have the trigger fire? They function a bit like an AND statement? And when 1 of them is false, it does nothing?

I wonder then why it didn't work. It's also pretty tough to trouble shoot.. is there some kind of 'console.log' function you can use to print out debug data to review in the Show Trace section?

PimDoos commented 9 months ago

I was going to say: Try out the HA DevTools to see when it returns true. But... I think I found a mistake. There should be an and operator in the template which adds both checks together. So this is definitely a bug in the script 🤐

PimDoos commented 9 months ago

This should correctly run both checks and only return true if both checks pass. https://github.com/PimDoos/ha-sessy-examples/blob/79f28e73d2a5bd0c63bc9818c698a58f44b8a8b1/blueprints/script/sessy/sessy-full-charge.yaml#L140