I’m running HA on a Raspberry Pi in a IoT project where I measure sea water and air temperature with a sensor that sends data regularly to a sensor (MQTT).
I have set up sensors that shows real time values on meters and generates historical data. So far so good.
I also need the temperature value to be exported as a text file to an other server on internet where date will be further used. I have got help an ideas from this community to come to where I’m now. But still missing the very last step.
- id: '1701867996210'
alias: Save Temperature to Local File
description: ''
trigger:
- platform: state
entity_id: sensor.vattentemperatur_1
action:
- service: notify.Vattentemperatur
data_template:
message: ' {{ states.sensor.vattentemperatur_1.state }}'
“Since we’ll be running these commands from sensors or service calls, interactive SSH isn’t an option so we must go password-less (plus its a security best practice). So to start we need to generate an identity…”
I have chosen to use (yes, not so secure sshpass…) to send files to the server.
Considering this I don’t understand why I can’t send data as in the script upload.sh.
Directly from the terminal it works perfectly but in automation - no.
sshpass installed in docker homeassistant
I would be happy if someone could help me with this very last step so I could get my temperature web page to work.
Yes, that’s usually the issue there are limited items installed in the container. While you could install it there, when you rebuild or upgrade the container anything you install will need to be reinstalled.
As an alternative design consider running a script on the destination system that uses the HA REST API to pull the data.
The terminal is running on the host. HA is running in a docker container on the host.
When you execute a command from the terminal that is occurring within the host. When you have HA execute a command via an automation it executes within the container.
Think of the container as a separate environment from the Host with its own set of software So in this case rhe sshpass program is installed on the host but not in the container.
To upload a file from the containers you’ll need to do one of these
A) find a utility that is installed that you can use.
B) install the utility in the container that you need
C) use a different design
#!/bin/bash
# Set variables
REMOTE_USER="******"
REMOTE_HOST="*****"
REMOTE_PATH="*****"
REMOTE_PORT=22
PASSWORD="*****"
# Get the last line of temp_color.txt and save it to last.color_temp.txt
tail -n -1 temp_black.txt > last.black_temp.txt
tail -n -1 temp_red.txt > last.red_temp.txt
tail -n -1 temp_white.txt > last.white_temp.txt
# Save the current date in the desired format to datum.txt
echo "$(date +'%e/%-m %R')" > datum.txt
# Copy last_temp.txt and datum.txt to the remote server
sshpass -p "$PASSWORD" scp -P "$REMOTE_PORT" -o StrictHostKeyChecking=no last.black_temp.txt last.red_temp.txt last.white_temp.txt datum.txt "$REMOTE_USER"@"$REMOTE_HOST":"$REMOTE_PATH">
# Also upload to raabadarna
source ./upload_raabad.sh
Core has been updated twice and OS once. Uploading runs as desired without any interaction from me.
Use an automation on Home Assistant start to run the addapk shell command. You don’t need to be installing it every time the upload script runs. Just once at Home Assistant start.
Yes after a core update HA always restarts, and more importantly after a core update the supervisor completely rebuilds the container, and any customisations (eg packages you have added) will be lost.