homeassistant-powercalc icon indicating copy to clipboard operation
homeassistant-powercalc copied to clipboard

[FR] Run playbook based on status (w/o service call)

Open EddyK69 opened this issue 3 months ago • 21 comments

Checklist

  • [X] I have filled out the template to the best of my ability.
  • [X] This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • [X] This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

n/a

Describe the solution you'd like

I would love to have the option to run a playbook based on the status of the device, without the need of a start and stop service.

states:
  idle: idle.csv
  pause: pause.csv
  off: off.csv

Every time the status changes, the playbook should start from the beginning

Describe alternatives you've considered

n/a

Additional context

A status change should stop the current running playbook and start the playbook mapped to the new state.

EddyK69 avatar Mar 27 '24 22:03 EddyK69

I will consider this. Do you use YAML or GUI?

bramstroker avatar Mar 29 '24 19:03 bramstroker

Implemented with #2170

See: https://homeassistant-powercalc.readthedocs.io/en/latest/strategies/playbook.html#active-playbook-based-on-state-trigger

I cannot do for OFF state as this is a special case in Powercalc, and needs fundamental changes on different places.

Will be in next release.

You could test it by installing the master branch with HACS.

bramstroker avatar Mar 30 '24 09:03 bramstroker

@EddyK69 Ok, I only implemented in YAML yet. Will have a look if I can also implement for the GUI.

bramstroker avatar Mar 30 '24 16:03 bramstroker

Thnx! That was a quick one! Is use the GUI btw. Will test this asap

EddyK69 avatar Mar 30 '24 16:03 EddyK69

Added for GUI with #2176

bramstroker avatar Mar 31 '24 07:03 bramstroker

Thnx, but cannot download Master via HACS: get a 404 on https://github.com/bramstroker/homeassistant-powercalc/releases/download/master/powercalc.zip

EddyK69 avatar Apr 01 '24 10:04 EddyK69

That's strange it shouldn't try to download the release as it's not actually as release. Might be a bug in HACS. Pretty sure I was able to install this way in the past. Don't have time to investigate that further atm. Will do a new release for Powercalc soon.

bramstroker avatar Apr 01 '24 13:04 bramstroker

Hi @bramstroker I tried to download master many times, and it always failed with 404. I think the access right for that folder are restricted to your account. Maybe you can make the path to https://github.com/bramstroker/homeassistant-powercalc/releases/download/master/powercalc.zip public readable?!

erkr avatar Apr 06 '24 17:04 erkr

@erkr Strange you both are having issues. I cannot make that path available as master is not a release, but just the main branch where releases are made from. A zip file is only build when a new release / version is being issued. HACS shouldn't try to download powercalc.zip, but rather clone the repository. Maybe something changed in HACS why this is not working anymore, it was working in the past. I'll have a look.

bramstroker avatar Apr 06 '24 17:04 bramstroker

I have found following issue on HACS issue tracker: https://github.com/hacs/integration/issues/3513

It was working in the past, but apparently it does not work anymore when the integration uses zip releases, which is what powercalc does and is the preferred way. According to the developer of HACS it's not something which will be fixed in HACS, which is a pitty. So there it not much I can do unfortunately.

If you want to you could download manually. And replace config/custom_components/powercalc with the contents of custom_components/powercalc. It's a littlebit more work, but it's essentially the same as HACS automates.

Screenshot 2024-04-06 at 19 29 17

bramstroker avatar Apr 06 '24 17:04 bramstroker

@bramstroker Great you found out that it simply doesn't work. I propose to just remove the master from the release list. You currently release so actively, that I can wait for the next one ☺️

I recall from another project that a version must be set in the manifest when you copy the files manually

erkr avatar Apr 06 '24 18:04 erkr

@bramstroker Great you found out that it simply doesn't work. I propose to just remove the master from the release list. You currently release so actively, that I can wait for the next one ☺️

That not something I can fix in Powercalc, that's also a HACS issue. When zip_release is used they should just hide the master branch from the list. That's also suggested by other integration developers in the issue link I shared. https://github.com/hacs/integration/issues/3513#issuecomment-1949471720

I recall from another project that a version must be set in the manifest when you copy the files manually

I'm pretty confident that's not required. You can just overwrite the files manually and restart and it should load the new code.

bramstroker avatar Apr 07 '24 05:04 bramstroker

Today I'm with family, but I will give it a try tomorrow 👍

erkr avatar Apr 07 '24 07:04 erkr

Added for GUI with #2176

@bramstroker I cannot find the settings in the GUI I'm afraid. Where can I find it?

Scherm­afbeelding 2024-04-14 om 16 51 56 Scherm­afbeelding 2024-04-14 om 16 52 25

EddyK69 avatar Apr 14 '24 14:04 EddyK69

@EddyK69 I see, there was actually a problem with the translation keys, causing the labels not correctly rendered. Will be fixed in next version.

The correct field is this one:

Screenshot 2024-04-19 at 08 16 05

bramstroker avatar Apr 19 '24 06:04 bramstroker

@bramstroker Thnx. Found the hidden field 😄

But unfortunately i cannot get it working the way i thought it should:

I configured a device with a simple on/off state: Scherm­afbeelding 2024-04-19 om 18 19 36

And added 2 playbooks in de config/powercalc/playbooks folder:

cat test-on.csv 
1,10
2,20
3,30
5,50
10,100
cat test-off.csv 
1,100
2,50
3,30
5,20
10,10

The 'On' playbook seems to work, but the 'Off' playbook doesn't. After switching the device to Off, power is set to 0 immediately and after switching it On again, the playbook doesn't seem to start from the beginning:

https://github.com/bramstroker/homeassistant-powercalc/assets/13943630/c3482d27-86f6-4408-ab46-705086e774b0

I would expect that the playbook start over again after every state-change, right?

EddyK69 avatar Apr 19 '24 16:04 EddyK69

@EddyK69 Did you see one of my first comments after I implemented? https://github.com/bramstroker/homeassistant-powercalc/issues/2160#issuecomment-2027983565

off state cannot be used for playbook.

I will have a quick look if I can find a way to implement without needing to modify too much.

bramstroker avatar Apr 19 '24 17:04 bramstroker

Have good news, because it was a quicky. Should be fixed with #2210

bramstroker avatar Apr 19 '24 17:04 bramstroker

@EddyK69 Did you see one of my first comments after I implemented? #2160 (comment)

off state cannot be used for playbook.

Oops, missed that :|

EddyK69 avatar Apr 19 '24 17:04 EddyK69

Have good news, because it was a quicky. Should be fixed with #2210

Quick indeed! Wil try it again soon, thnx!

EddyK69 avatar Apr 19 '24 17:04 EddyK69

Have good news, because it was a quicky. Should be fixed with #2210

Quick indeed! Wil try it again soon, thnx!

Will be in next release. not sure when yet. maybe this weekend

bramstroker avatar Apr 19 '24 17:04 bramstroker

Still doesn't seem to work unfortunately :(

https://github.com/bramstroker/homeassistant-powercalc/assets/13943630/43438603-14a6-4f7d-984b-799282689603

EddyK69 avatar May 02 '24 22:05 EddyK69

@EddyK69 You are sure you are at v1.11.8 now? Or are you running beta version of powercalc?

bramstroker avatar May 03 '24 06:05 bramstroker

@EddyK69 You are sure you are at v1.11.8 now? Or are you running beta version of powercalc? @bramstroker Yep, I'm sure. Scherm­afbeelding 2024-05-03 om 11 07 04

It worked once: switching ON started started to increase the power (see below how the playbooks are defined) and switiching OFF started to decrease, only once! After the OFF playbook was finished, i switched ON & OFF and nothing happens. I tried to restart the integration but that did not fix it.

Scherm­afbeelding 2024-05-03 om 11 05 56
cat test-on.csv 
1,10
2,20
3,30
5,50
10,100
cat test-off.csv 
1,100
2,50
3,30
5,20
10,10

EddyK69 avatar May 03 '24 09:05 EddyK69

Ok thanks for the extra information. Will have a look if I can reproduce and fix.

bramstroker avatar May 03 '24 09:05 bramstroker

Should be fixed with #2229. According to the unit tests this should fix the issue. I'll also do some testing on my develop HA instance.

bramstroker avatar May 03 '24 09:05 bramstroker

Ok thanks for the extra information. Will have a look if I can reproduce and fix.

Thnx! Just updated to V1.12.0 and it seems that is now not starting the OFF-playbook anymore :(

EddyK69 avatar May 03 '24 09:05 EddyK69

It's working for me now:

https://github.com/bramstroker/homeassistant-powercalc/assets/2345875/91fe1fcc-c441-4a88-b6fa-0b7e01200ca3

You can try by editing config/custom_components/powercalc/strategy/playbook.py and add following to line 95: https://github.com/bramstroker/homeassistant-powercalc/blob/09f2feca624ed8f772d6f3d504ed8786c330a172/custom_components/powercalc/strategy/playbook.py#L95

Restart HA afterwards.

bramstroker avatar May 03 '24 10:05 bramstroker

Thanx @bramstroker for the quick fix! Wil try out this weekend

EddyK69 avatar May 03 '24 13:05 EddyK69

Yep, works perfectly now! Thanx @bramstroker !

EddyK69 avatar May 04 '24 16:05 EddyK69