|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | ###############################################################################
|
3 |
| -# deployhasp.sh - Configure Home Assistnat for HASP integration, then download |
| 3 | +# deployhasp.sh - Configure Home Assistant for HASP integration, then download |
4 | 4 | # the latest HASP automation package and modify for the provided device name
|
5 | 5 | ###############################################################################
|
6 | 6 |
|
|
68 | 68 | echo " packages: !include_dir_named packages"
|
69 | 69 | echo "==========================================================================="
|
70 | 70 | else
|
71 |
| - sed -i 's/^homeassistant:.*/homeassistant:\n packages: !include_dir_named packages/' configuration.yaml |
| 71 | + if grep "^homeassistant:" configuration.yaml > /dev/null |
| 72 | + then |
| 73 | + sed -i 's/^homeassistant:.*/homeassistant:\n packages: !include_dir_named packages/' configuration.yaml |
| 74 | + elif grep "^default_config:" configuration.yaml > /dev/null |
| 75 | + then |
| 76 | + sed -i 's/^default_config:.*/default_config:\nhomeassistant:\n packages: !include_dir_named packages/' configuration.yaml |
| 77 | + else |
| 78 | + echo "===========================================================================" |
| 79 | + echo "WARNING: Could not add package declaration to 'configuration.yaml'." |
| 80 | + echo " Please add the following statement to your configuration:" |
| 81 | + echo "default_config:" |
| 82 | + echo " packages: !include_dir_named packages" |
| 83 | + echo "===========================================================================" |
| 84 | + fi |
72 | 85 | fi
|
73 | 86 | fi
|
74 | 87 |
|
75 | 88 | # Enable recorder if not enabled to persist relevant values
|
76 | 89 | if ! grep "^recorder:" configuration.yaml > /dev/null
|
77 | 90 | then
|
78 | 91 | echo "recorder:" >> configuration.yaml
|
| 92 | + echo " include:" >> configuration.yaml |
| 93 | + echo " domains:" >> configuration.yaml |
| 94 | + echo " - automation" >> configuration.yaml |
| 95 | + echo " - binary_sensor" >> configuration.yaml |
| 96 | + echo " - input_boolean" >> configuration.yaml |
| 97 | + echo " - input_number" >> configuration.yaml |
| 98 | + echo " - input_select" >> configuration.yaml |
| 99 | + echo " - input_datetime" >> configuration.yaml |
| 100 | + echo " - input_text" >> configuration.yaml |
| 101 | + echo " - weather" >> configuration.yaml |
79 | 102 | fi
|
80 | 103 |
|
81 | 104 | # Warn if MQTT is not enabled
|
82 | 105 | if ! grep "^mqtt:" configuration.yaml > /dev/null
|
83 | 106 | then
|
84 |
| - echo "===========================================================================" |
85 |
| - echo "WARNING: Required MQTT broker configuration not setup in configuration.yaml" |
86 |
| - echo "HASP WILL NOT FUNCTION UNTIL THIS HAS BEEN CONFIGURED! The embedded option" |
87 |
| - echo "offered my Home Assistant is buggy, so deploying Mosquitto is recommended." |
88 |
| - echo "" |
89 |
| - echo "Home Assistant MQTT configuration: https://www.home-assistant.io/docs/mqtt/broker/#run-your-own" |
90 |
| - echo "Install Mosquitto: sudo apt-get install mosquitto mosquitto-clients" |
91 |
| - echo "===========================================================================" |
92 |
| -fi |
93 |
| - |
94 |
| -# Hass has a bug where packaged automations don't work unless you have at least one |
95 |
| -# automation manually created outside of the packages. Attempt to test for that and |
96 |
| -# create a dummy automation if an empty automations.yaml file is found. |
97 |
| -if grep "^automation: \!include automations.yaml" configuration.yaml > /dev/null |
98 |
| -then |
99 |
| - if [ -f automations.yaml ] |
| 107 | + if ! grep '"domain": "mqtt"' .storage/core.config_entries > /dev/null |
100 | 108 | then
|
101 |
| - if [[ $(< automations.yaml) == "[]" ]] |
102 |
| - then |
103 |
| - echo "WARNING: empty automations.yaml found, creating DUMMY automation for package compatibility" |
104 |
| - echo "- action: []" > automations.yaml |
105 |
| - echo " id: DUMMY" >> automations.yaml |
106 |
| - echo " alias: DUMMY Can Be Deleted After First Automation Has Been Added" >> automations.yaml |
107 |
| - echo " trigger: []" >> automations.yaml |
108 |
| - fi |
| 109 | + echo "===========================================================================" |
| 110 | + echo "WARNING: Required MQTT broker configuration not setup in configuration.yaml" |
| 111 | + echo " or added under Configuration > Integrations." |
| 112 | + echo "" |
| 113 | + echo "HASP WILL NOT FUNCTION UNTIL THIS HAS BEEN CONFIGURED! The embedded option" |
| 114 | + echo "offered my Home Assistant is buggy, so deploying Mosquitto is recommended." |
| 115 | + echo "" |
| 116 | + echo "Home Assistant MQTT configuration: https://www.home-assistant.io/docs/mqtt/broker/#run-your-own" |
| 117 | + echo "Install Mosquitto: sudo apt-get install mosquitto mosquitto-clients" |
| 118 | + echo "===========================================================================" |
109 | 119 | fi
|
110 | 120 | fi
|
111 | 121 |
|
|
123 | 133 | # rename text in contents of files
|
124 | 134 | sed -i -- 's/plate01/'"$hasp_device"'/g' $hasp_temp_dir/packages/plate01/hasp_plate01_*.yaml
|
125 | 135 | sed -i -- 's/plate01/'"$hasp_device"'/g' $hasp_temp_dir/hasp-examples/plate01/hasp_plate01_*.yaml
|
| 136 | + sed -i -- 's/plate01/'"$hasp_device"'/g' $hasp_temp_dir/packages/hasp_plate01_lovelace.txt |
126 | 137 |
|
127 | 138 | # rename files and folder - thanks to @cloggedDrain for this loop!
|
128 | 139 | mkdir $hasp_temp_dir/packages/$hasp_device
|
|
156 | 167 | fi
|
157 | 168 | done
|
158 | 169 | rm -rf $hasp_temp_dir/hasp-examples/plate01
|
| 170 | + # rename the lovelace UI file |
| 171 | + mv $hasp_temp_dir/packages/hasp_plate01_lovelace.txt $hasp_temp_dir/packages/hasp_${hasp_device}_lovelace.txt |
159 | 172 | fi
|
160 | 173 |
|
161 | 174 | # Check to see if the target directories already exist
|
|
193 | 206 |
|
194 | 207 | echo "==========================================================================="
|
195 | 208 | echo "SUCCESS! Restart Home Assistant to enable HASP device $hasp_device"
|
| 209 | +echo "Check the file packages/hasp_${hasp_device}_lovelace.txt for a set of" |
| 210 | +echo "basic Lovelace UI elements you can include in your configuration to manage" |
| 211 | +echo "the new device." |
0 commit comments