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

That looks ok, I don’t know what could be going wrong. Does the script work when you run it manually?

You can try this example (haven’t tested it myself):

https://hassagent.readthedocs.io/en/latest/sensor-command-automation-and-script-examples/#command-grab-screenshot-using-powershell

Hey @cemara,

You can use the display on/off commands in the latest beta.

For the webcam detection: you could use netcam studio. It’s free for 2 sources. Enable motion detection for your webcam (blob detection works fine). Then create a rule that triggers on motion detection. Use RunApp as the action, and curl.exe as the path (you can get curl here). Then enter this as the argument: -d "" http://your_hass_ip:8123/api/webhook/your_webhook_name.

In HA, create an automation:

- alias: whatever you want
  initial_state: true
  mode: single
  trigger:
    platform: webhook
    webhook_id: your_webhook_name
  action:
    - service: switch.turn_on
      data:
        entity_id: switch.your_display_on_switch

Restart HA afterwards.

1 Like

That’s the script I’m using. I can call it directly in Windows and it places the image in /config/www but from HASS.Agent it doesn’t do anything.

Finally checked the Event Viewer and found this:

> Error Message = File D:\HA\HAscreenshot.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
> Fully Qualified Error ID = UnauthorizedAccess

Ran PowerShell as Administrator and ran
Set-ExecutionPolicy RemoteSigned and now it works.

Good catch! Added to the example

@SamKr I have been keeping an eye on development of this with interest for a while now and decided to jump in and give it a try. Firstly, thank you for all your effort and work on this!

I’ve searched this ever expanding thread and haven’t been able to find anyone posting about the same issue, but I am finding that sensors are not holding their states between restarts of Home Assistant.

For example, I have enabled the MicrophoneActive and WebcamActive sensors, which are super useful for triggering status updates when in Teams Meetings (I’m really looking forward to be able to filter the process using these in the next release for more accuracy). These show up and work flawlessly in Home Assistant, until I restart at which point they then show as unknown until I go back into HASS.Agent and store and activate them again, or wait for the first update of state to be sent. What this means is that I always miss the first state change after a restart as they are changing from unknown instead of off or on. If I change my automations to ignore the from state and just use the to state, one of the automations gets triggered whenever they first update after a restart.

I have temporarily created input_boolean helpers to store the states between restarts and have automations that update the helpers whenever they change. This is a decent workaround, but doesn’t actually resolve the issue I am experiencing. Maybe it’s just me that’s having this issue? I am running this on a work laptop that is preventing the notifications from working (ports are being blocked by security software which I am unable to circumvent), so maybe a message is sent to the laptop from Home Assistant to query the states after a restart that is not being received?

I’m no expert on MQTT, but I can see in MQTT Explorer that the Retain flag is not set on the messages in my instance. I’m not sure if setting this would solve this, or if this is something I can do, or needs to be changed in HASS.Agent?

Any advice on how to resolve this and remove the need for the input_booleans would be appreciated. I did think of creating an automation to query and update the states after a restart (i.e. using an event trigger of start), but I don’t know what I need to do to query it (i.e. what I need in the action). Given the ports on the laptop are blocked, it would need to query the MQTT broker. Also wondering if I am alone with this issue and it’s being caused by the ports being blocked on my laptop, or it’s something others are experiencing. TIA.

Just switched over from IOTLink and really impressed so far - especially the windows gui!

In IOTLink you have the command to turn off/on the display. Is this possible in Hass.Agent?

I can’t seem to figure out the commands? You do have a YAML example of creating a light entity for the display in your docs.

Thanks!

I also wanted to turn on/off the display.
for turning display on, i send a ctrl key press via HA to the pc.

For turning off i tried to install nircmd, which has a function nircmd.exe monitor off.
That is working very well, when i type that in the cmd and hit Enter.

But if i try to add a command, it does not work.

I have set the external tools to “C:\Windows\System32\cmd.exe” with interpreter name “cmd”.

and try to set a CustomExecutorCommand:
grafik

But if i try to execute this command via HA, there is nothing happening.

This is great and I just started using this app. I’m very interested in using the LastActive sensor to turn off my office lights when I haven’t been actively using my computer for a while. But it seems like sensor is always active, even if I’m not making any user input.

The description says “Provides a datetime value containing the last moment the user provided any input.” but it doesn’t seem to work that way for me.

Hi @robertwigley, thanks!

This is a known issue that I’m working on, for now you can use a PublishAllSensors command. Run that in an automation after a HA restart, and all values will get republished.

Hopefully that’ll be useful for you until a more permanent fix is in place :slight_smile:

Hi @sebbaT, those have been added in the latest beta: Release 2022.13.0-beta2 · LAB02-Research/HASS.Agent · GitHub

1 Like

Hey @flyinglow, it might be that you have a tool running that prevents your system from going to sleep by emulating input. The sensor simply retrieves the value from Windows, and it’s based on mouse & keyboard input.

OK. That’s good to know. Thanks.

Is PublishAllSensors a service? I can’t see it in Developer Tools. I couldn’t find it in the documentation either. Could you advise how to use it?

If I can create an automation to do this on start, it will completely get rid of the problem. Thanks.

It’s a command in HASS.Agent. You can then use this trigger in your automation:

  trigger:
    - platform: homeassistant
      event: start

Then simply call the command you created (depending on what type you made it):

    - service: switch.turn_on
      data:
        entity_id: switch.hass_agent_publish_all_sensors

Excellent! I hadn’t looked in the commands. This should be added to the Wiki/Docs. I can confirm that this has solved the problem. Thank you.

trigger:
  - platform: homeassistant
    event: start
action:
  - service: button.press
    target:
      entity_id: button.laptop_publish_all_sensors

Great! I’ll add it :slight_smile:

Thanks @SamKr, that was a good tip. I tried diligently closing any software that could have been running in the background and didn’t find anything. Then I started thinking about hardware devices and when I unplugged my game controller I found it was the source of the “user activity” that was making the LastActive sensor always be active.

3 Likes

I’ve done a bit a searching but can’t seem to find a solution. HASS.Agent is installed and working, I can see all of my configured sensors sending data in MQTTExplorer and I have an automation checking a sensor, which works so all looks good?

However, I’m getting this error in mosquitto broker every 5 seconds:

...
2022-09-10 16:16:21: New connection from 192.168.1.228:50413 on port 1883.
error: received null username or password for unpwd check
2022-09-10 16:16:21: Client <unknown> disconnected, not authorised.
2022-09-10 16:16:26: New connection from 192.168.1.228:50416 on port 1883.
error: received null username or password for unpwd check
2022-09-10 16:16:26: Client <unknown> disconnected, not authorised.
...

My device name in HASS.Agent does not have spaces, dots, etc, and is just a string “PAVILLION”. The topic is unchanged, “homeassistant” and I can see this working in MQTTExplorer. The device is seen in Devices and added to a dashboard. I’ve created an automation from the device and it works successfully turning on/off a smart plug based on battery change. These are only issues I’ve picked up on reading through this thread, have I missed something?

Chris

LOVE THIS thanks so much for creating it. So I am not the most tech savvy person, I have HASS Agent up and running and all is good I want to use the Wake on Lan, I configured NirSoft in the external tools, ensured WoL was set up correct on the windows box but am lost on how to get a button into HA in order to make it work. I did go through the doc’s and remember seeing some kind of example, do I just need to put that YAML into HA to make this work? Sorry for what is probably obvious but I am just not tracking. Thanks!

EDIT- found the example

  • platform: wake_on_lan
    name: “TEST_W10_x64_01”
    mac: “00-00-00-00-00-00”
    host: 10.0.0.5
    broadcast_address: 10.0.0.255
    turn_off:
    service: switch.turn_on
    data:
    entity_id: switch.test_w10_x64_01_cmd_shutdown

Can’t say I understand it all though. looking at the HA WoL info not sure if all the above is needed?

EDIT2- So I tried but failed. End result I am going for is to have the computer off, tap a switch on my phone (Android) in the HA App and have the computer start up.

Final Edit- Holy Crap- I figured it out. LOL Scared money can’t win so I decided to pull up my big boy pants and give it a shot, I mean what could go wrong right? Got lucky- but it works like a champ now!

Hi all!
'm trying now to test the Poweshell Screenshoot script example in the documentation, but I’m having problems since PowerShell complains that the network path is not found. I assume that thet script as written in the documentation assumes that Windows has a network folder from the Home Assistant instance mapped into windows, which is the one in this variable: "$Path = “\HOMEASSISTANT\config\www”. the Path in that variable has to be local in the Windows machine, right?

Thanks!
/Nacho