Login control - Logout your users via automation

Simple component that adds service that logs out (clear its refresh tokens) specific user. Used as a workaround for https://github.com/home-assistant/home-assistant/issues/30124 .

Example use:

- alias: 'Logout all guests at midnight'
  trigger:
    platform: time
    at: '00:00:00'
  action:
    service: token_control.clear_refresh_tokens
    data:
      user_id: [YOUR USER ID HERE]

Hi! I put the “login_control” folder under in my “custom_components” and restarted Home Assistant. I do not have a token_control.clear_refresh_tokens service.

Is there something else I’m supposed to do?

EDIT 1 - put “token_control:” in your Home Assistant Config

EDIT 2
I get an error when trying to use the service:

"Call-service API error. Error Message: ‘NoneType’ object has no attribute ‘refresh_tokens’ "

Yes, you have to out login_control: in your configuration.

I have answered you on github regarding error messages (just to keep things structured).

Hi, I did:

  • I put the “login_control” folder under in my “custom_components” and restarted Home Assistant.
  • I put “login_control:” in my Home Assistant Config (configuration.yaml).
  • I checked the configuration and got the error: Component error: login_control - Integration “login_control” not found.
    Please am I missing something?
    Thank you!

Integration was missing a version. Please try downloading it again now.

I downloaded it again but the error continues.
Thanks

I was only able to get it to work when replacing token_control with login_control in init.py and in manifest.json.
I made a Pull Request with the change.
Thanks.

Merged, thanks.

Is this skill still working?

I tried here but it is generating the error “Integration error: login_control - Integration ‘login_control’ not found.” when checking for updates.

in the py file it is like login_control and I also added it to configuration.yaml

Yes, I’m still using it without issues in HA 2023.2.5.

Try adding it that way:

  1. Just add login_control folder to your custom components (without adding it to the config)
  2. Restart HA
  3. Add config
  4. Restart again

@matejdro

I’m only just getting off the ground with adding things to Home Assistant.
Any assistance would be greatly appreciated.

re Matejdro / login_control in Github I see
login_control/init.py
login_control/manifest.json
login_control/services.yaml

Do I copy these 3 files to the folder homeassitant/custom_components/login_control

in what file and where do I place the following

  • alias: ‘Logout all guests at midnight’
    trigger:
    platform: time
    at: ‘00:00:00’
    action:
    service: token_control.clear_refresh_tokens
    data:
    user_id: [YOUR USER ID HERE]

Yes, you just copy those 3 files and then add login_control: to your configuration.yaml file.

Then you can use automation editor to create an automation that triggers clear refresh tokens service, no need to create this copy paste yaml automation.

@matejdro
Thank you for your reply. As I am new to all of this I’m having difficulty trying to add the service to the Automation

I have the trigger but cannot find the required service in the service list.

Try finding “token_control.clear_refresh_tokens” in the list. If not, it’s likely that the plugin did not load. Did you restart HA after adding it to the custom components folder? Check Settings → System → logs → full log to see if anything is mentioned there.

thank you,
I completely overlooked [quote=“matejdro, post:12, topic:156930”]
and then add login_control: to your configuration.yaml file
[/quote]

Have now added “Login Control: clear_refresh_tokens”

I had added user_id: “John Schols” to services.yaml and then changed to user_id: ‘John Schols’ and then also user_id: John Schols all hae come up with the same error. HAve I missed something?

Error in log.
Logger: homeassistant.helpers.service
Source: helpers/service.py:561
First occurred: 14:20:06 (1 occurrences)
Last logged: 14:20:06

Unable to parse services.yaml for the login_control integration: expected a dictionary for dictionary value @ data[‘clear_refresh_tokens’][‘fields’][‘user_id’]

this is the text in the services.yaml

clear_refresh_tokens:
fields:
user_id: John Schols

description: User ID (String) of the user that should get refresh tokens cleared

Thanks.

You need to use user ID, not user name.

In HA, go to Configuration → Persons → Users → Press on your user name. Window will open that will show your ID.

Again, there is so much I don’t know yet. Thanks. However still failing. Is it only in the services.yaml that I need to add the user_id or does it need to be added into
the ‘init’.py also. Is there anything else I need to be adding?


login control 003

Regards, John

Ah, no, you should add user_id to the action, not to the services.yaml

Oh golly, sorry to be such a pain.
Where exactly in the new automation does this go?

Huh, it should display service data or service parameters somewhere. Otherwise, sorry, it appears that this is only compatible with the YAML automations: Automation YAML - Home Assistant