{"id":13484,"date":"2022-07-18T17:28:46","date_gmt":"2022-07-18T17:28:46","guid":{"rendered":"https:\/\/www.rjt.org.uk\/home\/?post_type=home_assistant_tip&#038;p=13484"},"modified":"2025-03-27T14:20:41","modified_gmt":"2025-03-27T14:20:41","slug":"create-a-camera-for-screenshots-in-hass-agent","status":"publish","type":"home_assistant_tip","link":"https:\/\/www.rjt.org.uk\/home\/archives\/home-assistant-tip\/create-a-camera-for-screenshots-in-hass-agent\/","title":{"rendered":"Create a &#8220;camera&#8221; for screenshots in HASS.AGENT"},"content":{"rendered":"\n<p>Currently <a href=\"https:\/\/www.hass-agent.io\/2.0\/#\">HASS.AGENT<\/a> does not provide a way to easily create a screen shot camera entity, but it is possible as follows<\/p>\n\n\n\n<p>Create a Powershell script<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$Path = \"\\\\HOMEASSISTANT\\config\\www\"\n# Make sure that the directory to keep screenshots has been created, otherwise create it\nIf (!(test-path $path)) {\nNew-Item -ItemType Directory -Force -Path $path\n}\nAdd-Type -AssemblyName System.Windows.Forms\n$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds\n# Get the current screen resolution\n$image = New-Object System.Drawing.Bitmap($screen.Width, $screen.Height)\n# Create a graphic object\n$graphic = [System.Drawing.Graphics]::FromImage($image)\n$point = New-Object System.Drawing.Point(0, 0)\n$graphic.CopyFromScreen($point, $point, $image.Size);\n$cursorBounds = New-Object System.Drawing.Rectangle([System.Windows.Forms.Cursor]::Position, [System.Windows.Forms.Cursor]::Current.Size)\n# Get a screenshot\n[System.Windows.Forms.Cursors]::Default.Draw($graphic, $cursorBounds)\n# $screen_file = \"$Path\\\" + $env:computername + \"_\" + $env:username + \"_\" + \"$((get-date).tostring('yyyy.MM.dd-HH.mm.ss')).png\"\n$screen_file = \"$Path\\\" + $env:computername + \"-screenshot.png\"\n# Save the screenshot as a PNG file\n$image.Save($screen_file, [System.Drawing.Imaging.ImageFormat]::Png)<\/pre>\n\n\n\n<p>You might need to change the path.  Note it assumes you have the SAMBA plugin enabled on your Homeassistance instance. <\/p>\n\n\n\n<p>Next add this script as a command in HASS.Agent<\/p>\n\n\n\n<p>Now go into Home Assistant and Integrations and add a Generic Camera pointing it as the file using the full url.  e.g<\/p>\n\n\n\n<p>http:\/\/homeassistant.local:8123\/local\/EBONY-VIII-screenshot.png<\/p>\n\n\n\n<p>with your computer name where EBONY-VIII is.<\/p>\n\n\n\n<p>Finally set up a simple automation to update the screen shot as often as you want.  With a condition to check the PC is on.<\/p>\n\n\n\n<p>This camera can be displayed with the standard Picture Entity Card.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">alias: Screenshot Ebony\ndescription: ''\ntrigger:\n  - platform: time_pattern\n    minutes: \/2\ncondition:\n  - condition: state\n    entity_id: switch.ebony_viii\n    state: 'on'\naction:\n  - service: button.press\n    data: {}\n    target:\n      entity_id: button.ebony_take_screenshot\nmode: single<\/pre>\n","protected":false},"template":"","class_list":["post-13484","home_assistant_tip","type-home_assistant_tip","status-publish","hentry","comments-off"],"_links":{"self":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip\/13484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip"}],"about":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/types\/home_assistant_tip"}],"wp:attachment":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/media?parent=13484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}