Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to switch to remote vcontrold #10

Merged
merged 3 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions vcontrold/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ options:
tty: "/dev/ttyUSB0"
refresh: 30
device_id: "2098"
remote_vcontrol: false
vcontrol_host: localhost
vcontrol_port: 3002
debug: false
commands:
- getTempA:FLOAT
Expand Down Expand Up @@ -58,6 +61,9 @@ schema:
tty: "str"
refresh: "int"
device_id: "str"
remote_vcontrol: "bool"
vcontrol_host: "str"
vcontrol_port: "int"
debug: "bool"
commands:
- "str"
Expand Down
6 changes: 5 additions & 1 deletion vcontrold/rootfs/etc/services.d/vclient_pub/run
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ else
export MQTT_PASSWORD=$(bashio::services mqtt "password")
export MQTT_TOPIC="openv"

export VCONTROL_HOST=$(bashio::config 'vcontrol_host')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid misunderstandings when remote_vcontrol is set to false, we should force the host/port to localhost. What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's even better, but only if you can deactivate them in the config UI IMHO (like adding a ?)
I would avoid forcing values in the script without being able to deactivate them for the end user so one is not confused and inputs are not in conflict with the actual values that are used to run the service.
If this is not possible we can still rename the config flag and explain - e.g. using a flag "start local vcontrold". Will test it later.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about turning it around? If vcontrol_host/vcontrol_port is set, then it is assumed that it's a remote vcontrold.
If it's unset - the vcontrold is started and localhost:3002 is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, also a good idea. How about this: We remove the remote-switch, set defaults to null (hidden under advanced options) and assume local vcontrold on localhost:3002 in case there is no value set?
That way we stay backwards-compatible and have the same look-and-feel in the configs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will push a test version later today/tonight once I have tested it locally.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Schm1tz1

Thanks for the contribution!
Could you maybe also integrate a remote mqtt configuration? I tried my luck here:
https://github.com/ppuetsch/homeassistant-vcontrol/tree/main

However, I wasn't able to (sucessfully) test it as during my test still the main docker images (without the changes to the run scripts) were used. I right now don't have the time to dig deeper into that - but If you like the changes, maybe you can integrate them into your PR.

Thank you :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
it's about the docker image pull policy. To test locally, simply comment out the image-line so it gets re-created upon installation:
https://github.com/Schm1tz1/homeassistant-vcontrol/blob/remote-vcontrold/vcontrold/config.yaml#L70

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, it's about the docker image pull policy. To test locally, simply comment out the image-line so it gets re-created upon installation: https://github.com/Schm1tz1/homeassistant-vcontrol/blob/remote-vcontrold/vcontrold/config.yaml#L70

Thank you! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alexandre-io - took a look at the suggested changes and also the suggestions made by @ppuetsch. I think if we let the end-user switch by simply setting a different host/port or staying with the defaults we don't break anything, stay backwards-compatible and keep the configuration simple. To avoid restarts of the services due to non-existing vcontrold I needed to add a dummy tail-f service. Please have a look. It is already running in my basement :-)

export VCONTROL_PORT=$(bashio::config 'vcontrol_port')
bashio::log.info "Setting vcontrold host to $VCONTROL_HOST and port to $VCONTROL_PORT ..."

## Run your program
while sleep $refresh_rate; do
vclient -h 127.0.0.1 -p 3002 -f /etc/vcontrold/1_mqtt_commands.txt -t /etc/vcontrold/2_mqtt.tmpl -x /etc/vcontrold/3_mqtt_pub.sh
vclient -h $VCONTROL_HOST -p $VCONTROL_PORT -f /etc/vcontrold/1_mqtt_commands.txt -t /etc/vcontrold/2_mqtt.tmpl -x /etc/vcontrold/3_mqtt_pub.sh
bashio::log.info "Looping vclient..."
done
fi
6 changes: 5 additions & 1 deletion vcontrold/rootfs/etc/services.d/vclient_sub/run
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ else
export MQTT_PASSWORD=$(bashio::services mqtt "password")
export MQTT_TOPIC="openv"

bashio::log.info "Setting vcontrold host and port ..."
export VCONTROL_HOST=$(bashio::config 'vcontrol_host')
export VCONTROL_PORT=$(bashio::config 'vcontrol_port')

## Run your program
while true ; do
mosquitto_sub -v -h $MQTT_HOST -p $MQTT_PORT -u $MQTT_USER -P $MQTT_PASSWORD -t "$MQTT_TOPIC/#" | while read -r payload
Expand All @@ -28,7 +32,7 @@ else
if [[ $topic =~ "/set" ]]; then
command=$(echo $topic | cut -d'/' -f2)
bashio::log.info "Sending command: [${command}]: ${value}"
vclient -h 127.0.0.1 -p 3002 -o /dev/stdout -c "${command} ${value}"
vclient -h $VCONTROL_HOST -p $VCONTROL_PORT -o /dev/stdout -c "${command} ${value}"
fi
done
sleep $refresh_rate
Expand Down
10 changes: 9 additions & 1 deletion vcontrold/rootfs/etc/services.d/vcontrold/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

# Declare variables
declare config_tty
declare config_deviceid
declare config_commands
declare config_debug
declare remote_vcontrol

## Get the 'message' key from the user config options.
config_tty=$(bashio::config 'tty')
config_deviceid=$(bashio::config 'device_id')
config_debug=$(bashio::config 'debug')
config_commands=$(bashio::config 'commands')
remote_vcontrol=$(bashio::config 'remote_vcontrol')

# Cleanup scripts
rm /etc/vcontrold/1_mqtt_commands.txt || /bin/true
Expand Down Expand Up @@ -51,5 +54,10 @@ else
sed -i "s/#DEBUG#/n/g" /etc/vcontrold/vcontrold.xml
fi

bashio::log.info "Remote vcontrol set to $remote_vcontrol..."

## Run your program
exec /usr/sbin/vcontrold -n -U root -d $config_tty
if [ "$remote_vcontrol" = "false" ] ; then
bashio::log.info "Starting local vcontrold..."
exec /usr/sbin/vcontrold -n -U root -d $config_tty
fi
9 changes: 9 additions & 0 deletions vcontrold/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ configuration:
device_id:
name: "Device ID"
description: "Viessmann Gerätekennung (2098 => V200KW2 , 2053 => GWG_VBEM, 20CB => VScotHO1 , 2094 => V200KW1)"
remote_vcontrol:
name: "Connect to remote vcontrold"
description: "An, falls mit vcontrold auf anderem Rechner verbunden werden soll und aus, um vcontrold auf localhost zu starten (z.B. bei verbundenem Optolink-Kabel)"
vcontrol_host:
name: "Vcontrold Host"
description: "vcontrold host für die Verbindung (default: localhost)"
vcontrol_port:
name: "Vcontrold Port"
description: "vcontrold für die Verbindung (default: 3002)"
debug:
name: "Debug"
description: "Ausgabe von Debug-Nachrichten"
Expand Down
9 changes: 9 additions & 0 deletions vcontrold/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ configuration:
device_id:
name: "Device ID"
description: "The device identifier. (2098 => V200KW2 , 2053 => GWG_VBEM, 20CB => VScotHO1 , 2094 => V200KW1)"
remote_vcontrol:
name: "Connect to remote vcontrold"
description: "Set to true if you want to connect to a remote vcontrold and false to run vcontrold on localhost (e.g. Optolink cable connected)"
vcontrol_host:
name: "Vcontrold Host"
description: "vcontrold host to connect to (default: localhost)"
vcontrol_port:
name: "Vcontrold Port"
description: "vcontrold port to connect to (default: 3002)"
debug:
name: "Debug"
description: "Output of debug messages"
Expand Down