Skip to content

Commit

Permalink
Merge pull request #84 from aderusha/dev
Browse files Browse the repository at this point in the history
HASP v0.39
  • Loading branch information
aderusha authored Feb 11, 2020
2 parents 8618c55 + 516aee3 commit 0014cf5
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 42 deletions.
10 changes: 10 additions & 0 deletions Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ Utilize the provided Home Assistant automations to control and interact with the

Time to remove the training wheels and learn to send commands to and from the panel via MQTT.

----

## Frequently Asked Questions

* **Can I install HASP outside of North America?** While the various power supply options for the HASP electronics should offer a solution which can handle line voltage in most countries, the physical installation of the device probably won't work outside of North America. There is no international standard for the size and shape of workboxes, so things like screw hole locations and overall mounting dimensions used for the HASP are unlikely to work in any workbox outside of North America.
* **Can I use HASP with \<Some Home Automation System\>**? If your home automation system can send Nextion commands as MQTT payloads, then yes. Getting it all to work is going to take a lot of work, but it's possible.
* **Can I run HASP without a neutral wire?** Like most smart devices, a HASP installation will require a neutral wire available in the box you're mounting into.

----

## HASwitchPlate Architecture

The complete HA SwitchPlate build consists of 4 physical components:
Expand Down
68 changes: 42 additions & 26 deletions Home_Assistant/deployhasp.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
###############################################################################
# deployhasp.sh - Configure Home Assistnat for HASP integration, then download
# deployhasp.sh - Configure Home Assistant for HASP integration, then download
# the latest HASP automation package and modify for the provided device name
###############################################################################

Expand Down Expand Up @@ -68,44 +68,54 @@ then
echo " packages: !include_dir_named packages"
echo "==========================================================================="
else
sed -i 's/^homeassistant:.*/homeassistant:\n packages: !include_dir_named packages/' configuration.yaml
if grep "^homeassistant:" configuration.yaml > /dev/null
then
sed -i 's/^homeassistant:.*/homeassistant:\n packages: !include_dir_named packages/' configuration.yaml
elif grep "^default_config:" configuration.yaml > /dev/null
then
sed -i 's/^default_config:.*/default_config:\nhomeassistant:\n packages: !include_dir_named packages/' configuration.yaml
else
echo "==========================================================================="
echo "WARNING: Could not add package declaration to 'configuration.yaml'."
echo " Please add the following statement to your configuration:"
echo "default_config:"
echo " packages: !include_dir_named packages"
echo "==========================================================================="
fi
fi
fi

# Enable recorder if not enabled to persist relevant values
if ! grep "^recorder:" configuration.yaml > /dev/null
then
echo "recorder:" >> configuration.yaml
echo " include:" >> configuration.yaml
echo " domains:" >> configuration.yaml
echo " - automation" >> configuration.yaml
echo " - binary_sensor" >> configuration.yaml
echo " - input_boolean" >> configuration.yaml
echo " - input_number" >> configuration.yaml
echo " - input_select" >> configuration.yaml
echo " - input_datetime" >> configuration.yaml
echo " - input_text" >> configuration.yaml
echo " - weather" >> configuration.yaml
fi

# Warn if MQTT is not enabled
if ! grep "^mqtt:" configuration.yaml > /dev/null
then
echo "==========================================================================="
echo "WARNING: Required MQTT broker configuration not setup in configuration.yaml"
echo "HASP WILL NOT FUNCTION UNTIL THIS HAS BEEN CONFIGURED! The embedded option"
echo "offered my Home Assistant is buggy, so deploying Mosquitto is recommended."
echo ""
echo "Home Assistant MQTT configuration: https://www.home-assistant.io/docs/mqtt/broker/#run-your-own"
echo "Install Mosquitto: sudo apt-get install mosquitto mosquitto-clients"
echo "==========================================================================="
fi

# Hass has a bug where packaged automations don't work unless you have at least one
# automation manually created outside of the packages. Attempt to test for that and
# create a dummy automation if an empty automations.yaml file is found.
if grep "^automation: \!include automations.yaml" configuration.yaml > /dev/null
then
if [ -f automations.yaml ]
if ! grep '"domain": "mqtt"' .storage/core.config_entries > /dev/null
then
if [[ $(< automations.yaml) == "[]" ]]
then
echo "WARNING: empty automations.yaml found, creating DUMMY automation for package compatibility"
echo "- action: []" > automations.yaml
echo " id: DUMMY" >> automations.yaml
echo " alias: DUMMY Can Be Deleted After First Automation Has Been Added" >> automations.yaml
echo " trigger: []" >> automations.yaml
fi
echo "==========================================================================="
echo "WARNING: Required MQTT broker configuration not setup in configuration.yaml"
echo " or added under Configuration > Integrations."
echo ""
echo "HASP WILL NOT FUNCTION UNTIL THIS HAS BEEN CONFIGURED! The embedded option"
echo "offered my Home Assistant is buggy, so deploying Mosquitto is recommended."
echo ""
echo "Home Assistant MQTT configuration: https://www.home-assistant.io/docs/mqtt/broker/#run-your-own"
echo "Install Mosquitto: sudo apt-get install mosquitto mosquitto-clients"
echo "==========================================================================="
fi
fi

Expand All @@ -123,6 +133,7 @@ then
# rename text in contents of files
sed -i -- 's/plate01/'"$hasp_device"'/g' $hasp_temp_dir/packages/plate01/hasp_plate01_*.yaml
sed -i -- 's/plate01/'"$hasp_device"'/g' $hasp_temp_dir/hasp-examples/plate01/hasp_plate01_*.yaml
sed -i -- 's/plate01/'"$hasp_device"'/g' $hasp_temp_dir/packages/hasp_plate01_lovelace.txt

# rename files and folder - thanks to @cloggedDrain for this loop!
mkdir $hasp_temp_dir/packages/$hasp_device
Expand Down Expand Up @@ -156,6 +167,8 @@ then
fi
done
rm -rf $hasp_temp_dir/hasp-examples/plate01
# rename the lovelace UI file
mv $hasp_temp_dir/packages/hasp_plate01_lovelace.txt $hasp_temp_dir/packages/hasp_${hasp_device}_lovelace.txt
fi

# Check to see if the target directories already exist
Expand Down Expand Up @@ -193,3 +206,6 @@ fi

echo "==========================================================================="
echo "SUCCESS! Restart Home Assistant to enable HASP device $hasp_device"
echo "Check the file packages/hasp_${hasp_device}_lovelace.txt for a set of"
echo "basic Lovelace UI elements you can include in your configuration to manage"
echo "the new device."
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ automation:
- service: mqtt.publish
data_template:
topic: 'hasp/plate01/command/espupdate'
payload: ''
payload: ''
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ automation:
trigger:
- platform: time_pattern
# Matches every minute
seconds: 00
seconds: 0
condition:
- condition: template
value_template: '{{ states.sun.sun.attributes.elevation <= 10 }}'
Expand Down
Binary file modified Home_Assistant/hasppackages.tar.gz
Binary file not shown.
32 changes: 32 additions & 0 deletions Home_Assistant/migrate-hasp-107.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
###############################################################################
# migrate-hasp-107.sh - Modify an existing Home Assistant configuration
# with HASP deployed to accomodate breaking changes in v107
###############################################################################

# Confirm that we're working in the .homeassistant folder by checking for configuration.yaml
if [ ! -f configuration.yaml ]
then
echo "WARNING: 'configuration.yaml' not found in current directory."
echo "Searching for Home Assistant 'configuration.yaml'..."
configfile=$(find / -name configuration.yaml 2>/dev/null)
count=$(echo "$configfile" | wc -l)
if [ $count == 1 ]
then
configdir=$(dirname "${configfile}")
cd $configdir
echo "INFO: configuration.yaml found under: $configdir"
else
echo "ERROR: Failed to locate the active 'configuration.yaml'"
echo " Please run this script from the homeassistant"
echo " configuration folder for your environment."
exit 1
fi
fi

# If the user has already deployed HASP devices...
if [ -d packages ]
then
# Search through existing packages to see if we have any "view:" statements to remove as they have been deprecated
find packages -name "hasp_*.yaml" -exec sed -i '/[[:blank:]]view\:/d' {} +
fi
4 changes: 3 additions & 1 deletion Home_Assistant/packages/hasp_demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# these and/or replace with your own devices

weather:
- platform: met
- platform: nws
api_key: [email protected]
name: nws

alarm_control_panel:
- platform: manual
Expand Down
31 changes: 31 additions & 0 deletions Home_Assistant/packages/hasp_plate01_lovelace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- path: plate01
title: plate01
badges:
- entity: binary_sensor.plate01_connected
- entity: sensor.plate01_status
cards:
- type: entities
title: plate01 Page Selection
entities:
- input_number.hasp_plate01_activepage
- input_number.hasp_plate01_pagebutton1page
- input_text.hasp_plate01_pagebutton1label
- input_number.hasp_plate01_pagebutton2page
- input_text.hasp_plate01_pagebutton2label
- input_number.hasp_plate01_pagebutton3page
- input_text.hasp_plate01_pagebutton3label
- type: entities
title: plate01 Colors
entities:
- input_number.hasp_plate01_selectedforegroundcolor
- input_number.hasp_plate01_selectedbackgroundcolor
- input_number.hasp_plate01_unselectedforegroundcolor
- input_number.hasp_plate01_unselectedbackgroundcolor
- type: entities
title: plate01 automations
entities:
- automation.hasp_plate01_00_firsttimesetup
- type: entities
title: Light
entities:
- light.plate01_backlight
16 changes: 8 additions & 8 deletions Home_Assistant/packages/plate01/hasp_plate01_00_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,52 +67,52 @@ input_text:
input_number:
hasp_plate01_pagebutton1page:
name: plate01 Page 1 Page
icon: mdi:format-list-numbered
icon: mdi:numeric
min: 0
max: 9
step: 1
hasp_plate01_pagebutton2page:
name: plate01 Page 2 Page
icon: mdi:format-list-numbered
icon: mdi:numeric
min: 0
max: 9
step: 1
hasp_plate01_pagebutton3page:
name: plate01 Page 3 Page
icon: mdi:format-list-numbered
icon: mdi:numeric
min: 0
max: 9
step: 1
hasp_plate01_activepage:
name: plate01 Active Page
icon: mdi:format-list-numbered
icon: mdi:numeric
min: 0
max: 9
step: 1
hasp_plate01_alarmcode1:
name: plate01 AlarmCode1
icon: mdi:format-list-numbered
icon: mdi:numeric
min: -1
max: 9
step: 1
initial: -1
hasp_plate01_alarmcode2:
name: plate01 AlarmCode2
icon: mdi:format-list-numbered
icon: mdi:numeric
min: -1
max: 9
step: 1
initial: -1
hasp_plate01_alarmcode3:
name: plate01 AlarmCode3
icon: mdi:format-list-numbered
icon: mdi:numeric
min: -1
max: 9
step: 1
initial: -1
hasp_plate01_alarmcode4:
name: plate01 AlarmCode4
icon: mdi:format-list-numbered
icon: mdi:numeric
min: -1
max: 9
step: 1
Expand Down
2 changes: 1 addition & 1 deletion Home_Assistant/packages/plate01/hasp_plate01_p2_clock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ automation:
trigger:
platform: time_pattern
# Matches every minute
seconds: 00
seconds: 0
condition:
- condition: state
entity_id: 'binary_sensor.plate01_connected'
Expand Down
8 changes: 4 additions & 4 deletions Home_Assistant/packages/plate01/hasp_plate01_p2_weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ automation:
- alias: hasp_plate01_p2_Weather
trigger:
- platform: state
entity_id: weather.met_no
entity_id: weather.nws
- platform: state
entity_id: 'binary_sensor.plate01_connected'
- platform: homeassistant
Expand All @@ -23,12 +23,12 @@ automation:
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[6].txt'
payload_template: '"{{state_attr("weather.met_no","temperature")|int}}°F"'
payload_template: '"{{state_attr("weather.nws","temperature")|int}}°F"'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[7].font'
payload_template: '{% if states.weather.met_no.state|length <= 6 -%}3{% elif (states.weather.met_no.state|length > 6) and (states.weather.met_no.state|length <= 10) %}2{% elif (states.weather.met_no.state|length > 10) and (states.weather.met_no.state|length <= 15) %}1{% else %}0{%- endif %}'
payload_template: '{% if states.weather.nws.state|length <= 6 -%}3{% elif (states.weather.nws.state|length > 6) and (states.weather.nws.state|length <= 10) %}2{% elif (states.weather.nws.state|length > 10) and (states.weather.nws.state|length <= 15) %}1{% else %}0{%- endif %}'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[7].txt'
payload_template: '"{{states.weather.met_no.state|wordwrap(20, wrapstring="\\r")|title}}"'
payload_template: '"{{states.weather.nws.state|wordwrap(20, wrapstring="\\r")|title}}"'

0 comments on commit 0014cf5

Please sign in to comment.