HASS.Agent: Windows client to receive notifications, use commands, sensors, quick actions and more!

I’m only now experimenting with HASS.Agent; and it would be quite useful to have a switch(es) so that I can stop-start a win service with powershell [or any other method].

ex:

Stop-service -Name "Servicename"  
Start-service -Name "Servicename"

What would be the best approach - is it even possible, at the time?

edit:

Ups… hadn’t see the command “Powershell” … :no_mouth:
My bad.

edit2:

Hmmm, “;” doesn’t seem to work to add more commands in one line:

Stop-Service -Name "servicename"; Start-Sleep -Seconds 2; Start-Service -Name "servicename"

Still… Restart-Service should do the trick.

1 Like

Have you been able to resolve this ?
It seems some sensor will create that issue. You need to remove them in the config folder. Sometimes you need to remove everything and restart or it still crash.
Right now, I am trying one sensor at a time. I got the cpu load working and the monitor for 2 days.
The GPU load will work for a few minutes/hours and will crash and need to be removed.
May be it 's not the sensor but the quantity of sensors too. I am just going on by one, but I still don’t understand why it doesn’t work on my desktop PC while it’s working on my kids computer in the living-room.

So if someone have figured it out, please let me know.

Here is the error I get, when it crash and I reboot and crash again.

2022-12-22 21:41:33.436 -05:00 [INF] [MQTT] Initial registration completed
2022-12-22 21:43:46.590 -05:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
 ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory`1 buffer)
2022-12-22 21:55:56.741 -05:00 [INF] [MEDIA] New state: Idle
2022-12-22 22:05:52.362 -05:00 [INF] [MEDIA] New state: Paused
2022-12-22 23:01:37.416 -05:00 [INF] [MEDIA] New state: Idle

Solution: Just realized, the broker was not started in HA.

Installed and configured, however, MQTT is getting the ‘failed’ message and I don’t know why… any thoughts?

I’m having an issue getting Commands scripts to execute successfully. The below Command to Lock my PC. What am I missing, or have incorrectly created?

  • Everything is ‘running’ in HASS.Agent on my PC
  • IoTLink service is disabled
  • I’ve rebooted HA and my PC

Note, similar commands work via IoTLink.

UPDATE 1: I noticed I can execute the ‘lock’ by pressing the button available from within the HA MQTT Integration. Leading me to believe the connection works, my script is malformed.

UPDATE 2: I changed the Entity Type to Lock and added in an Automation, I was able to get the lock function to work. I still don’t understand why the script as written below doesn’t work.

UPDATE 3: What I am not understanding is the script here works, and I don’t know why. The only thing I see is the Type is ‘lock’, but it is devoid of a ‘topic’. What’s going on here?

Script that works:

pc1_lock:
  alias: PC1 - Lock
  sequence:
  - device_id: 55413b3bf326988202ea74b42e109126
    domain: lock
    entity_id: lock.pc1_lock
    type: lock
  mode: single
  icon: mdi:lock-outline

hass-agent

Script:

computer_lock:
  sequence:
  - service: mqtt.publish
    data:
      topic: homeassistant/button/PC1/PC1_lock
      payload: ''
  mode: single
  alias: Computer - Lock

Is it possible to run a windows batch file?

I have a sensor set for Session State changes. It works for me locking/logging on/off a Windows session. However, if I simply reboot HA, I’m given the ‘Unknown’ state. My understanding is ‘Retain Flag’ should help in this regard, but it does not. Suggestions?

Edit: I notice in HA MQTT, the latest messages for this sensor are either Locked or Unlocked. I’m not certain how to check if the message has actually been retained for the sensor it was originally sent for.

Edit:

See this HASS.Agent Issue…
Bug: Retain flag not set for MQTT sensors · Issue #239 · LAB02-Research/HASS.Agent (github.com)

I’m having this issue as well. I have to delete integration for each PC then restart HA for new machines to be discovered.

Hi,
Then i send a notification to my sons desktop it does not show then i plays a game in fullscreen. Am i doing anything wrong or is it not possible to show it? It works then a app is not in fullscreen. Any ideas?

data:
  title: Platsinformation
  message: Pappa har åkt hemifrån
  data:
    duration: 3
    image: http://192.168.1.252:8123/local/FredrikBW.jpg`

Then we changed priority for Hass.agent app on my sons computer it high. Then i showed the notification.

1 Like

Hi, i can’t get MonitorWake to work. When the pc turns the screen off either with windows internal setting or with monitorsleep from HASS.Agent i can’t run any commands from HA, i have tried with monitorwake and differnt key commands such as enter and space. It seems like no commands from HA works when the state of the pc is ‘Locked’ Any ideas? thanks.

Does anyone know if there is a way to trigger Focus Assist in Windows using HASS.Agent? It would be really useful to be able to switch it on/off when going into/out of Teams meetings, especially for when sharing your screen.

I’m not quite sure why this isn’t a built in option in Windows settings, as they have one for ‘When I’m duplicating my display’, but that only works when you are physically duplicating your display to another screen. With so many meetings and presentations taking place online these days, it really ought to be built into Windows, but alas it is not. So I’m wondering if I can do this using HASS.Agent and Home Assistant instead.

I’ve already got ‘meeting detection’ working with the MicrophoneActive and MicrophoneProcess sensors, which turns one of my smart bulbs red/off and plays an annoucement on an Amazon Echo when entering/exiting a meeting. Would like to add this as additional functionality. :slight_smile:

I notice that the author hasn’t been active on this discussion for years, so I’ll post this question on GitHub as well. Nonetheless, maybe someone can help me?

I have set up an HA automation where the trigger is on a sensor of the type UserNotificationStateSensor and I have configured it to activate the action on “NotPresent”:

Something like this:

platform: state
entity_id:
  - sensor.laptopuserstate
to: NotPresent

However, it almost never activates, except when I turn on my computer.

But what I actually need is a notification when my computer goes into Sleep mode or when it is shut off. What is the trigger for this use case?

In other words, what is the trigger that will activate whenever the screensaver or similar is activated?
Has anyone used something like this?

1 Like

Ok, now I see from this reply that maybe SessionStateSensor would be better for this purpose, so I’ll check.

If it works, then … stupid me :frowning:
… and thank you @ScottS !

And I’ll also try with

platform: state
entity_id:
  - sensor.laptopuserstate
from: AcceptsNotifications

@cvladan; years is a bit much :wink:

Been busy in december, things are calming down now. Hope to get some github/forum tickets done this weekend. Sorry everyone!

3 Likes

Hehe, sorry :slight_smile:

It’s not my fault. I haven’t been reading messages one-by-one.

I don’t know why, but the system still displays the warning “It’s been a while since we’ve seen SamKr — their last post was 2 years ago” at the top of the discussion, so I concluded you were not active for 2 years.

Thank you again for the great project.

.

Have you deleted my GitHub suggestion entered as issue?

I hope you’ve read my suggestion for improvement that I posted as an issue on GitHub, but I later saw that there is a separate YouTrack project for that.

By the way, how do I “dig up” the content of that issue I’ve entered because I think you deleted it and I want to enter it again, but this time in YouTrack, as you request. In that way I don’t have to type it again, since English is not my native language, and typing messages involves utilizing spelling, grammarly, and similar crap.

… really strange that GitHub does not notify user when issue is deleted via email :frowning:

Yeah, I find it strange he/they have not responded herein or github lately. Not sure what I donated for/to. One reason I’m drifting from IoTLink was the lack of support.

That’s weird, probably because I didn’t post much when I wrote that. I’ll look into your gh suggestion tomorrow - it’s actually the right way to do things; post suggestions on gh, then I’ll add them to youtrack :smiley:

1 Like

Bit harsh don’t you think? I’ve worked hundreds of hours on this project; in coding, in support and in docs. I have a full time job and a gf/social life, so I sink all my spare time into this. Last month was busy for me both professionally and personally, so yea I responded a bit slower since there’s not much wiggle room the amount of spare time.

Like I said in my previous post: things are getting back on track and I’ll do my best to catch up on tickets this weekend

6 Likes

I am often stingy with praise, but I want to specifically praise the author of this tool. I don’t know how he is with support, but the implementation of the application and the idea itself are absolutely phenomenal, in my opinion - which probably doesn’t matter too much :slight_smile:

So, all praise!
And thank you for your hard work.

That’s it.