Thank you for suggesting how to run the script so that the script can make edits to the Linux OS outside of the container in the docker. The solution turned out to be under the nose:smiley:. You probably know that OS Home Assistant works in docker, and docker itself is in Linux Alpine, so if you run the script through shell_command, the script cannot access the Linux root system from the container, and your example helped and it works.
To understand why your option is working, I will sign and post the links below
The script running through shell_command cannot make\add\create files in the root of the Linux OS
The script itself, which adds 3 links to the extreme versions of the NUT package (Network UPS Tools) to repositories.
#!/bin/bash
cat <<_EOF_ >> /etc/apk/repositories
http://nl.alpinelinux.org/alpine/edge/main
http://nl.alpinelinux.org/alpine/edge/community
http://nl.alpinelinux.org/alpine/edge/testing
_EOF_
apk add nut mc
Why is this necessary? For understanding, I share information
opened 12:58PM - 29 Nov 21 UTC
closed 02:29PM - 29 Nov 21 UTC
Home Assistant OS 6.6
Core 2021.11.5
Supervisor 2021.10.8
Add-on: Network UPS… Tools version: 0.9.0
***
This is an introduction and purely so that you understand what works for me and what I'm trying to configure in the NUT addon. First read below, so you will see that I have no problems with access to the UPS and I can manage the UPS, but I can only manage with Home Assistant on OpenWRT, and with OS Home Assistant it does not work.
***
For understanding, I will show you and describe below what works for me and why I want to do the same on OS Home Assistant. On the OpenWRT OS, I have a Home Assistant and there are nut packages and I can send commands to control the UPS, and I can also receive data from the UPS.
**Home Assistant on OpenWRT**
![image](https://user-images.githubusercontent.com/64090632/143869019-44ed1ec4-e949-425c-a139-f538588251b8.png)
**List of available commands for UPS control**
```
upscmd -u hassmon -p 12345678 [email protected] :3493 calibrate.start
upscmd -u hassmon -p 12345678 [email protected] :3493 calibrate.stop
upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.disable
upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.enable
upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.mute
upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.off
upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.on
upscmd -u hassmon -p 12345678 [email protected] :3493 load.off
upscmd -u hassmon -p 12345678 [email protected] :3493 load.off.delay
upscmd -u hassmon -p 12345678 [email protected] :3493 load.on
upscmd -u hassmon -p 12345678 [email protected] :3493 load.on.delay
upscmd -u hassmon -p 12345678 [email protected] :3493 shutdown.return
upscmd -u hassmon -p 12345678 [email protected] :3493 shutdown.stayoff
upscmd -u hassmon -p 12345678 [email protected] :3493 shutdown.stop
upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.start.deep
upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.start.quick
upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.stop
```
**All commands are processed and I get statuses from sensors**
![image](https://user-images.githubusercontent.com/64090632/143870704-0b8897a0-0418-418b-9d1a-c188f18cac99.png)
**I made a control panel for the UPS**
![image](https://user-images.githubusercontent.com/64090632/143868379-1cab5af9-95b4-4f1e-a44c-b1817c09070c.png)
```
switch:
- platform: command_line
switches:
ups_beeper:
command_on: upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.enable
command_off: upscmd -u hassmon -p 12345678 [email protected] :3493 beeper.disable
command_state: upsc [email protected] ups.beeper.status
value_template: '{{ is_state("sensor.ups_beeper_status","enabled") }}'
friendly_name: 'Звуковое оповещение'
ups_test_battery_deep:
command_on: upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.start.deep
command_off: upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.stop
command_state: upsc [email protected] ups.status
value_template: '{{ states("sensor.ups_self_test_result") == "In progress" }}'
friendly_name: 'Полный тест батареи'
ups_test_battery_quick:
command_on: upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.start.quick
command_off: upscmd -u hassmon -p 12345678 [email protected] :3493 test.battery.stop
command_state: upsc [email protected] ups.status
value_template: '{{ states("sensor.ups_self_test_result") == "In progress" }}'
friendly_name: 'Быстрый тест батареи'
```
**Added UPS via GUI NUT integration**
![image](https://user-images.githubusercontent.com/64090632/143867275-9064f4aa-1322-4a1b-9f6d-92395d68f5ff.png)
![image](https://user-images.githubusercontent.com/64090632/143867316-23b70ad0-527d-4bfe-aa7b-a15f370f26d2.png)
![image](https://user-images.githubusercontent.com/64090632/143867352-d2eac959-8581-43aa-8c41-65636b7ce66c.png)
***
Now let's get to the heart of the problem. The UPS is connected to the Synology NAS, and the Home Assistant runs on a virtual machine in the Synology NAS and does not have access to the UPS via a USB cable. I would like to send commands from Home Assistant to control the UPS, but I can't do this because OS Home Assistant runs on Linix Alpine OS, and it doesn't have a NUT package. I can't even run this command `upsc' through the terminal [email protected] `.
![image](https://user-images.githubusercontent.com/64090632/143867953-fa1f34d2-1ef1-48f4-ab06-76024c53ae08.png)
I installed the NUT addon, specified the following config and the launch was successful. I'm trying to connect via GUI integration to the NUT addon and get rejected. Tell me, how can I configure the NUT addon so that I can send commands to control the UPS and have sensors?
In the configuration , I specified the following
```
devices:
- config: []
driver: snmp-ups
name: ups
port: 192.168.1.200
mode: netclient
shutdown_host: 'false'
users:
- actions: []
instcmds:
- all
password: nutuser
username: nut!user
remote_ups_host: 192.168.1.200
remote_ups_name: ups
remote_ups_user: hassmon
remote_ups_password: '12345678'
```
The following is displayed in the log
```
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] nut: applying...
[fix-attrs.d] nut: exited 0.
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing...
-----------------------------------------------------------
Add-on: Network UPS Tools
Manage battery backup (UPS) devices
-----------------------------------------------------------
Add-on version: 0.9.0
You are running the latest version of this add-on.
System: Home Assistant OS 6.6 (amd64 / qemux86-64)
Home Assistant Core: 2021.11.5
Home Assistant Supervisor: 2021.10.8
-----------------------------------------------------------
Please, share the above information when looking for help
or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing...
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] nut.sh: executing...
[15:11:51] INFO: Setting mode to netclient...
[cont-init.d] nut.sh: exited 0.
[cont-init.d] nutclient.sh: executing...
[cont-init.d] nutclient.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[15:11:52] INFO: Starting the UPS monitor and shutdown controller...
0.000000 fopen /run/nut/upsmon.pid: No such file or directory
0.000287 Using power down flag file /etc/killpower
0.000495 UPS: [email protected] (slave) (power value 1)
0.000639 debug level is '1'
0.000779 Warning: running as one big root process by request (upsmon -p)
0.001013 Init SSL without certificate database
0.001906 Trying to connect to UPS [[email protected] ]
0.003780 Logged into UPS [email protected]
```
**I'm trying to connect to the NUT addon and I get this error**
![image](https://user-images.githubusercontent.com/64090632/143871538-0c4e764d-77e1-4aa6-b78e-af1598d12dcc.png)
![image](https://user-images.githubusercontent.com/64090632/143871561-7cc0aef6-4c90-4340-94b6-9f7227221a98.png)
opened 09:33PM - 07 Oct 21 UTC
closed 10:51AM - 19 Oct 21 UTC
integration: shell_command
### The problem
Shell command doesn’t work (It works well in the previous versi… on)
Hi,
I just realized that the remote sleep my QNAP using shell command is no longer working.
I ran the same command in Home Assistant Terminal and is able to Sleep my QNAP, but it cant sleep with the button I created in HA.
Herewith the command used to be working:
Appreciate your advice and help, thanks.
Regards,
Terence
### What is version of Home Assistant Core has the issue?
Home Assistant 2021.9.6
### What was the last working version of Home Assistant Core?
Home Assistant 2021.9.6
### What type of installation are you running?
Home Assistant Supervised
### Integration causing the issue
Shell_command
### Link to integration documentation on our website
https://www.home-assistant.io/integrations/shell_command/
### Example YAML snippet
```yaml
- platform: wake_on_lan
name: "WOL QNAP QTS"
mac: "XX:XX:XX:XX:XX:XX"
host: 192.168.8.9
turn_off:
service: shell_command.turn_off_qts
shell_command:
turn_off_qts: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'echo mem > /sys/power/state'"
```
### Anything in the logs that might be useful for us?
```txt
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'echo mem > /sys/power/state'`, return code: 255
05:32:42 – (ERROR) Shell Command
```
### Additional information
Log Details
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:115
Integration: Shell Command (documentation, issues)
First occurred: 05:32:42 (1 occurrences)
Last logged: 05:32:42
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'echo mem > /sys/power/state'`, return code: 255
NoneType: None
opened 09:33PM - 07 Oct 21 UTC
closed 10:51AM - 19 Oct 21 UTC
integration: shell_command
### The problem
Shell command doesn’t work (It works well in the previous versi… on)
Hi,
I just realized that the remote sleep my QNAP using shell command is no longer working.
I ran the same command in Home Assistant Terminal and is able to Sleep my QNAP, but it cant sleep with the button I created in HA.
Herewith the command used to be working:
Appreciate your advice and help, thanks.
Regards,
Terence
### What is version of Home Assistant Core has the issue?
Home Assistant 2021.9.6
### What was the last working version of Home Assistant Core?
Home Assistant 2021.9.6
### What type of installation are you running?
Home Assistant Supervised
### Integration causing the issue
Shell_command
### Link to integration documentation on our website
https://www.home-assistant.io/integrations/shell_command/
### Example YAML snippet
```yaml
- platform: wake_on_lan
name: "WOL QNAP QTS"
mac: "XX:XX:XX:XX:XX:XX"
host: 192.168.8.9
turn_off:
service: shell_command.turn_off_qts
shell_command:
turn_off_qts: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'echo mem > /sys/power/state'"
```
### Anything in the logs that might be useful for us?
```txt
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'echo mem > /sys/power/state'`, return code: 255
05:32:42 – (ERROR) Shell Command
```
### Additional information
Log Details
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:115
Integration: Shell Command (documentation, issues)
First occurred: 05:32:42 (1 occurrences)
Last logged: 05:32:42
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'echo mem > /sys/power/state'`, return code: 255
NoneType: None
I tried all the options, none of them worked, but inside the container it works
shell_command:
bash_scripts_del_video: bash /config/scripts/del_video_files.sh
bash_shell_del_video: bash /config/shell/del_video_files.sh
find_and_del: "find /media/AgentDVR/* -name *.* -mmin +1 -delete > /dev/null"
del_video01: /bin/bash /home/homeassistant/.homeassistant/scripts/del_video_files.sh
del_video02: sh /config/scripts/del_video_files.sh
And this is already a working option and I can now make changes to the Linux OS from the container where the Home Assistant is spinning
alias: 'System: Installing packages via SSH addon'
sequence:
- service: hassio.addon_stdin
data:
addon: a0d7b954_ssh
input: /config/scripts/install_packages.sh
mode: single
icon: mdi:blur
Текст на русском (Text in Russian)
Спасибо, что навели на мысль, как запустить скрипт, чтобы скрипт смог внести правки в ОС Linux за пределами контейнера в докере. Решение то оказалось под носом . Вам наверно известно, что OS Home Assistant работает в докере, а сам докер стоит в ОС Linux Alpine, так вот, если запускать скрипт через shell_command, то скрипт не может получить доступ к корневой системе Linux из контейнера, а ваш пример помог и он рабочий.
Для понимания почему ваш вариант рабочий ниже распишу и выложу ссылки
Скрипт запущенный через shell_command не может вносить\добавлять\создавать файлы в корне ОС Linux
Сам скрипт, который добавляет в repositories 3 ссылки на крайние версии пакета NUT (Network UPS Tools ).
#!/bin/bash
cat <<_EOF_ >> /etc/apk/repositories
http://nl.alpinelinux.org/alpine/edge/main
http://nl.alpinelinux.org/alpine/edge/community
http://nl.alpinelinux.org/alpine/edge/testing
_EOF_
apk add nut mc
Зачем это нужно? Для понимания делюсь инфой
Server and client. UPS Management · Issue #204 · hassio-addons/addon-nut · GitHub
Shell command doesn’t work (It works well in previous version) · Issue #57283 · home-assistant/core · GitHub
Shell command doesn’t work (It works well in previous version) · Issue #57283 · home-assistant/core · GitHub
Пробовал все варианты, ни один из них не отработал, а внутри контейнера это работает
shell_command:
bash_scripts_del_video: bash /config/scripts/del_video_files.sh
bash_shell_del_video: bash /config/shell/del_video_files.sh
find_and_del: "find /media/AgentDVR/* -name *.* -mmin +1 -delete > /dev/null"
del_video01: /bin/bash /home/homeassistant/.homeassistant/scripts/del_video_files.sh
del_video02: sh /config/scripts/del_video_files.sh
А это уже рабочий вариант и я теперь могу вносить изменения в ОС Linux из контейнера, где крутится Home Assistant
alias: 'Система: Установка пакетов через аддон SSH'
sequence:
- service: hassio.addon_stdin
data:
addon: a0d7b954_ssh
input: /config/scripts/install_packages.sh
mode: single
icon: mdi:blur