Hi,
I´m still trying to get a sensor which tells me, when a PC was last online. Nothing seems to survive an HA restart, so I gave the File Sensor a try but can´t get it to work right now:
It should work this way:
Powershell script creates a file with
get-computer-info | convertto-json > \\192.168.1.99\config\info\$env:computername.json
The file is formatted like this:
"OsBootDevice": "\\Device\\HarddiskVolume2",
"OsSystemDevice": "\\Device\\HarddiskVolume4",
"OsSystemDirectory": "C:\\WINDOWS\\system32",
"OsSystemDrive": "C:",
"OsWindowsDirectory": "C:\\WINDOWS",
"OsCountryCode": "49",
"OsCurrentTimeZone": 120,
"OsLocaleID": "0407",
"OsLocale": "de-DE",
"OsLocalDateTime": "\/Date(1624730214428)\/",
"OsLastBootUpTime": "\/Date(1624463894272)\/",
And this is part of the configuration.yaml for testing:
Not sure if the allowlist / whitelist part is correct that way.
whitelist_external_dirs:
- /media
- /config
- /config/info
allowlist_external_dirs:
- /config/info
- /config
- /media
sensor:
- platform: file
name: pc-office last boot
file_path: /config/info/pc-office.json
value_template: '{{ value_json.OS_LastBootUpTime}}'
- platform: file
name: pc-office os build
file_path: /config/info/pc-office.json
value_template: '{{ value_json.OS_BuildNumber}}'
With this config, the sensor are all in an “unknown” state.
Any Ideas? Thanks for help
Philipp