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

Hi, yeah it seems that worked. I removed old separate media player and notification integration and three devices popped up in autodiscovery. Thanks for hint

I setup a quick action which was working fine but stopped working. I just get a notification of failure and to check the logs, contents below:

2022-12-08 10:44:59.270 +00:00 [INF] [MAIN] HASS.Agent version: 2022.14.0
2022-12-08 10:44:59.282 +00:00 [INF] [SETTINGS] Config storage path: C:\Users\beuzi\AppData\Roaming\LAB02 Research\HASS.Agent\config
2022-12-08 10:44:59.616 +00:00 [INF] [SETTINGS] Configuration loaded
2022-12-08 10:44:59.620 +00:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2022-12-08 10:45:00.345 +00:00 [INF] [SETTINGS_QUICKACTIONS] Loaded 1 entities
2022-12-08 10:45:00.379 +00:00 [INF] [SETTINGS_COMMANDS] Loaded 1 entities
2022-12-08 10:45:02.882 +00:00 [FTL] [WUPDATE] Unable to query update status, Windows update seems to be corrupt: 0x80248014
System.Runtime.InteropServices.COMException (0x80248014): 0x80248014
   at WUApiLib.IUpdateSearcher.Search(String criteria)
   at HASS.Agent.Shared.Managers.WindowsUpdatesManager.GetUpdateList()
2022-12-08 10:45:03.253 +00:00 [INF] [SETTINGS_SENSORS] Loaded 7 entities
2022-12-08 10:45:03.271 +00:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2022-12-08 10:45:03.272 +00:00 [INF] [HOTKEY] Completed bind for 1 individual quickaction hotkeys
2022-12-08 10:45:04.041 +00:00 [INF] [LOCALAPI] Initializing ..
2022-12-08 10:45:04.042 +00:00 [INF] [MQTT] Identifying as device: CAVE-WINDOWS
2022-12-08 10:45:04.077 +00:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2022-12-08 10:45:04.080 +00:00 [INF] [MQTT] Connecting ..
2022-12-08 10:45:04.457 +00:00 [INF] [MQTT] Connected
2022-12-08 10:45:04.758 +00:00 [INF] [HASS_API] Home Assistant version: 2022.11.5
2022-12-08 10:45:05.032 +00:00 [INF] [HASS_API] System connected with http://homeassistant.local:8123
2022-12-08 10:45:05.081 +00:00 [INF] [MEDIA] Ready
2022-12-08 10:45:05.201 +00:00 [INF] [NOTIFIER] Ready
2022-12-08 10:45:06.103 +00:00 [INF] [MQTT] Initial registration completed
2022-12-08 10:45:06.515 +00:00 [INF] [LOCALAPI] listening on port 5115
2022-12-08 10:45:08.274 +00:00 [WRN] [HASS_API] Server returned 404 (not found) while getting entity state. This can happen after a server reboot, or if you've deleted the entity. If the problem persists, please file a ticket on github.
Entity: automation.office_speaker_input_select_toggle
Error message: Response status code does not indicate success: 404 (Not Found).
2022-12-08 10:48:59.634 +00:00 [INF] [HASS_API] [automation.office_speaker_input_select_toggle] Performing action: toggle
2022-12-08 10:48:59.639 +00:00 [FTL] [HASS_API] [automation.office_speaker_input_select_toggle] Error while processing action: Response status code does not indicate success: 404 (Not Found).
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at HADotNet.Core.BaseClient.Get[T](String path)
   at HADotNet.Core.Clients.StatesClient.GetState(String entityId)
   at HASS.Agent.HomeAssistant.HassApiManager.ProcessActionAsync(HassEntity entity, HassAction action)

Despite the initial 404 on the HASS_API the HASS.agent system status shows everything as “running” in green, plus when i go into the configuraiton and test connection it responds with “Connection Ok!”.

I’ve tried restarting home assistant and windows and removing and re-adding the integration; none have cured the issue. Any ideas of what i can try to fix?

I’ve an issue with sleep vs hibernate. It seems on the PC I’m testing it on, both commands effectively hibernate the PC, so the current state of the desktop and open windows is stored, but the PC is fully powered off.

The only way I can ‘sleep’ the PC is via the windows task bar button and selecting sleep, or setting a sleep state in my power settings, either of which cause the front power LED to flash when in sleep mode. A quick move of the mouse and it resumes.

Using the command above does the same thing as the HASS agent… i.e. causes hibernate not sleep.
Seems this is why:-

How to Create and Use a Windows 10/11 Sleep Mode Shortcut.

The answer appears to disable hibernate.
Hibernate can be disabled from an admin command prompt using ‘powercfg -h off’, and can be re-enabled using ‘powercfg -h on’ at a later date if you need it.

1 Like

Im sure this has ben asked but i searched and didnt see it i added the storage sensor but all it gives me in the entity in HA is the name of the dive… i dont know how to get the free space info

Use a template entity to extract the AvailableSpaceMB attribute from the storage sensor. I convert to GB in the example below.

  - name: computer_satellite_storage_c_freespace
    unique_id: 'unique_id_here'
    unit_of_measurement: GB
    state: "{{ ((states.sensor.computer_satellite_storage_c.attributes.AvailableSpaceMB/1000) | round(0) ) }}"
1 Like

Hello, the integration isn’t publishing through MQTT - Using Node-Red (Mosquitto mqtt-in) I can see the PC’s buttons and sensors reporting in every few seconds, but I cannot see the buttons or sensors listed anywhere in Home Assistant. I see the advice on the Troubleshooting page that i should “make sure that the MQTT user of both HASS.Agent and HA have access to the integration topic” but I do not know what this means or where to look (and the page does not say).

Thank you.

What do i put in unique id?


type: entity
entity: sensor.jesterod_pc_storage_c
- name: computer_satellite_storage_c_freespace
    unique_id: 'unique_id_here'
    unit_of_measurement: GB
    state: "{{ ((states.sensor.computer_satellite_storage_c.attributes.AvailableSpaceMB/1000) | round(0) ) }}"

Anything you want, really, as long as it is unique to your Home Assistant instance. I use a guid, generated by the Powershell New-Guid function. You can also use this web page:

https://www.uuidgenerator.net/guid

Hope this helps.

– John

So tried this


type: entity
entity: sensor.jesterod_pc_storage_c
- name: computer_satellite_storage_c_freespace
    unique_id: jes-pc-c_drive
    unit_of_measurement: GB
    state: "{{ ((states.sensor.jesterod_pc_storage_c.attributes.AvailableSpaceMB/1000) | round(0) ) }}"

Get this error

“ Configuration errors detected:
end of the stream or a document separator is expected (3:1)

1 | type: entity
2 | entity: sensor.jesterod_pc_storage_c
3 | - name: computer_satellite_stora …
-----^
4 | unique_id: jes-pc-c_drive
5 | unit_of_measurement: GB”

This stuff needs to go in a file called something like templates.yaml in your /config directory and your configuration.yaml needs to have the following line in it.

template: !include templates.yaml

Then templates.yaml should look like this (without the comments about indentation):

# The next line is indented two spaces.
  sensor:
# Indent two more spaces
    type: entity
    entity: sensor.jesterod_pc_storage_c
    - name: computer_satellite_storage_c_freespace
# Indent two more spaces, again
      unique_id: jes-pc-c_drive
      unit_of_measurement: GB
      state: "{{ ((states.sensor.jesterod_pc_storage_c.attributes.AvailableSpaceMB/1000) | round(0) ) }}

Make sure your indentation is corrrect and that you are using spaces, not tabs, to indent.

I’m using the HASS agent version 2022.14.0 on HA 2022.12.8 (the latest at time of writing) and just installed the combined HACS notification and media player addon which is on version 2022.11.9

Mostly, everything works fine (sensors, commands etc), but I do have a problem with the media player.

I can get media to play to the HASS agent PC if its a local media file, or TTS (radio would also be nice at some point!) but when playing the media, the pause button on the lovelace card (or via the media menu) does not respond, so once the media is playing, there is no way to stop it. I’ve not tried a service call yet… maybe that will work ?

Nothing in the logs, either in HA or the HASS agent folder.

OK… scrub all that… I restarted the HASS agent and its magically now working, and when I hit pause, a window also popups up on the target PC as well. All good it seems!

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