Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
EddyK69 opened this issue Mar 27, 2024 · 30 comments
Closed
3 tasks done

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

EddyK69 opened this issue Mar 27, 2024 · 30 comments
Labels
enhancement New feature or request playbook

Comments

@EddyK69
Copy link
Contributor

EddyK69 commented Mar 27, 2024

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • 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 EddyK69 added the enhancement New feature or request label Mar 27, 2024
@EddyK69 EddyK69 changed the title Run playbook based on status (w/o service call) [FR] Run playbook based on status (w/o service call) Mar 27, 2024
@bramstroker
Copy link
Owner

bramstroker commented Mar 29, 2024

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

@bramstroker
Copy link
Owner

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
Copy link
Owner

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

@EddyK69
Copy link
Contributor Author

EddyK69 commented Mar 30, 2024

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

@bramstroker
Copy link
Owner

Added for GUI with #2176

@EddyK69
Copy link
Contributor Author

EddyK69 commented Apr 1, 2024

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

@bramstroker
Copy link
Owner

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.

@erkr
Copy link

erkr commented Apr 6, 2024

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?!

@bramstroker
Copy link
Owner

@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
Copy link
Owner

I have found following issue on HACS issue tracker:
hacs/integration#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

@erkr
Copy link

erkr commented Apr 6, 2024

@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

@bramstroker
Copy link
Owner

@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.
hacs/integration#3513 (comment)

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.

@erkr
Copy link

erkr commented Apr 7, 2024

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

@EddyK69
Copy link
Contributor Author

EddyK69 commented Apr 14, 2024

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

@bramstroker
Copy link
Owner

@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

@EddyK69
Copy link
Contributor Author

EddyK69 commented Apr 19, 2024

@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:

Schermopname.2024-04-19.om.18.27.00.mov

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

@bramstroker
Copy link
Owner

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

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
Copy link
Owner

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

@EddyK69
Copy link
Contributor Author

EddyK69 commented Apr 19, 2024

@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
Copy link
Contributor Author

EddyK69 commented Apr 19, 2024

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

Quick indeed! Wil try it again soon, thnx!

@bramstroker
Copy link
Owner

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

@EddyK69
Copy link
Contributor Author

EddyK69 commented May 2, 2024

Still doesn't seem to work unfortunately :(

Schermopname.2024-05-03.om.00.00.35.mov

@bramstroker
Copy link
Owner

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

@EddyK69
Copy link
Contributor Author

EddyK69 commented May 3, 2024

@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

@bramstroker
Copy link
Owner

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

@bramstroker
Copy link
Owner

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.

@EddyK69
Copy link
Contributor Author

EddyK69 commented May 3, 2024

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 :(

@bramstroker
Copy link
Owner

It's working for me now:

Overview.Home.Assistant.mp4

You can try by editing config/custom_components/powercalc/strategy/playbook.py and add following to line 95:

Restart HA afterwards.

@EddyK69
Copy link
Contributor Author

EddyK69 commented May 3, 2024

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

@EddyK69
Copy link
Contributor Author

EddyK69 commented May 4, 2024

Yep, works perfectly now! Thanx @bramstroker !

@EddyK69 EddyK69 closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request playbook
Projects
None yet
Development

No branches or pull requests

3 participants