tobias-kuendig / hacompanion

Daemon that sends local hardware information to Home Assistant
MIT License
95 stars 15 forks source link

bug: custom script not updated. need systemctl --user restart hacompanion to refresh #18

Open Bram-diederik opened 2 years ago

Bram-diederik commented 2 years ago

I created a custom script. But it does not refresh to home assistant unless systemctl --user restart hacompanion is run.

running it local shows expected outcome.

daft@Blue-Mage:~$ apt-check.sh 
3
icon:mdi:update
packages:jami-all libnftables1 nftables 
[script.Upgradable_packages]
 name = "Upgradable Packages"
 path = "/usr/local/bin/apt-check.sh"
 icon = "mdi:script-text"
 type = "sensor"
#!/bin/bash
filename=/tmp/apt-check

if [ ! -f $filename ]
then
  apt-get -s --no-download dist-upgrade -V --fix-missing| grep '=>' | awk '{print$1}' > $filename
else
  file_time=$(stat --format='%Y' "$filename")
  current_time=`date +%s`
  if (( file_time < ( current_time - ( 60 * 5 ) ) )); then
    apt-get -s --no-download dist-upgrade -V --fix-missing| grep '=>' | awk '{print$1}' > $filename
  fi
fi
count=`cat $filename | wc -l`
if [ $count == 0 ] 
 then
  echo "0"
  echo "icon:mdi:check"
 else
  echo $count
  echo "icon:mdi:update"
  echo -n "packages:"
  tr '\n' ' ' < $filename
fi 
pschmitt commented 2 years ago

what's your hacompanion config?

Is your service running the whole time?

Bram-diederik commented 2 years ago
[homeassistant]
# Generate the token on the /profile page in Home Assistant
token = mytoken
# The display name of your device in Home Assistant
device_name = "mylaptop"
# Enter the full URL of your Home Assistant instance.
host = "https://mydomain:443"

[companion]
# New sensor values are sent to Home Assistant at this interval.
update_interval = "15s"
# The location, where all registration information for Home Assistant will be stored on your machine.
# You do not need to change this.
registration_file = "~/.config/hacompanion-registration.json"

[notifications]
# Where Home Assistant should send notifications to. Make sure to insert your
# local IP address here. Make sure the port is the same as in the `listen` setting below.
push_url = "http://mylaptophostname:8080/notifications"
# The IP and Port where the Notification server on your machine will listen.
# By default listens on port 8080 on all interfaces.
listen = "0.0.0.0:8080"

##
## Below are all available senors. Enable/Disable them as needed.
##

# Report the number of processes that are currently accessing your webcam.
# This will send the number as reported by `lsmod | grep uvcvideo`.
[sensor.webcam]
enabled = true
name = "Webcam Process Count"

# Report the CPU temperature of all cores.
# Note: Requires `lm-sensors` package to be installed locally.
[sensor.cpu_temp]
enabled = true
name = "CPU Temperature"
meta = { celsius = true }

# Report the CPU usage of all cores.
[sensor.cpu_usage]
enabled = true
name = "CPU Usage"

# Report the current system uptime since last boot.
[sensor.uptime]
enabled = true
name = "Last Boot"

# Report the current memory/swap usage.
[sensor.memory]
enabled = true
name = "Memory"

# Report the current battery charge.
# In case of multiple batteries, you can set which battery to monitor
# in the meta section. To see available batteries run
# `ls /sys/class/power_supply/`
[sensor.power]
enabled = true
name = "Power"
meta = { battery = "BAT0" }

# Report if the companion process is running on this machine.
[sensor.companion_running]
enabled = true
name = "Companion Is Running"

# Report if this machine has connection to a remote host.
# You can configure which host to ping in the meta section.
#[sensor.online_check]
#enabled = true
#name = "Is Online"
## Available modes are "http" and "ping".
## meta = { target = "192.168.1.1", mode = "ping" }
#meta = { target = "https://google.com", mode = "http" }

# Report the average system load in the last 1m, 5m and 15m.
[sensor.load_avg]
enabled = true
name = "Load Avg"

# Report the audio volume and mute state.
[sensor.audio_volume]
enabled = true
name = "Audio Volume"

## Register a custom sensor that is populated by a custom script.
## See the README for more details on this feature.
# [script.your_custom_script_sensor]
# path = "/path/to/your/script.sh"
## Attributes according to
## https://developers.home-assistant.io/docs/api/native-app-integration/sensors
# name = "Friendly name of your custom sensor"
# icon = "mdi:script-text"
# type = "sensor" # or binary_sensor
## unit_of_measurement = "%"
## device_class = "battery"

[script.Upgradable_packages]
 name = "Upgradable Packages"
 path = "/usr/local/bin/apt-check.sh"
 icon = "mdi:script-text"
 type = "sensor"
Bram-diederik commented 2 years ago

the laptop does go to sleep.

Bram-diederik commented 2 years ago

other sensors do get updated after a sleep of the laptop.