├── OpenSans-Light.ttf ├── OpenSans-Regular.ttf ├── menu_generator ├── html5sortable.min.js ├── pithy_screen_milan_example.yaml └── js-yaml.min.js ├── README.md └── LICENSE /OpenSans-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikosoft83/pithy_screen_menu_system/HEAD/OpenSans-Light.ttf -------------------------------------------------------------------------------- /OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikosoft83/pithy_screen_menu_system/HEAD/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /menu_generator/html5sortable.min.js: -------------------------------------------------------------------------------- 1 | var sortable=function(){"use strict";function c(e,t,n){if(void 0===n)return e&&e.h5s&&e.h5s.data&&e.h5s.data[t];e.h5s=e.h5s||{},e.h5s.data=e.h5s.data||{},e.h5s.data[t]=n}var v=function(e,t){if(!(e instanceof NodeList||e instanceof HTMLCollection||e instanceof Array))throw new Error("You must provide a nodeList/HTMLCollection/Array of elements to be filtered.");return"string"!=typeof t?Array.from(e):Array.from(e).filter(function(e){return 1===e.nodeType&&e.matches(t)})},y=new Map,t=function(){function e(){this._config=new Map,this._placeholder=void 0,this._data=new Map}return Object.defineProperty(e.prototype,"config",{get:function(){var n={};return this._config.forEach(function(e,t){n[t]=e}),n},set:function(e){if("object"!=typeof e)throw new Error("You must provide a valid configuration object to the config setter.");var t=Object.assign({},e);this._config=new Map(Object.entries(t))},enumerable:!1,configurable:!0}),e.prototype.setConfig=function(e,t){if(!this._config.has(e))throw new Error("Trying to set invalid configuration item: "+e);this._config.set(e,t)},e.prototype.getConfig=function(e){if(!this._config.has(e))throw new Error("Invalid configuration item requested: "+e);return this._config.get(e)},Object.defineProperty(e.prototype,"placeholder",{get:function(){return this._placeholder},set:function(e){if(!(e instanceof HTMLElement)&&null!==e)throw new Error("A placeholder must be an html element or null.");this._placeholder=e},enumerable:!1,configurable:!0}),e.prototype.setData=function(e,t){if("string"!=typeof e)throw new Error("The key must be a string.");this._data.set(e,t)},e.prototype.getData=function(e){if("string"!=typeof e)throw new Error("The key must be a string.");return this._data.get(e)},e.prototype.deleteData=function(e){if("string"!=typeof e)throw new Error("The key must be a string.");return this._data.delete(e)},e}(),E=function(e){if(!(e instanceof HTMLElement))throw new Error("Please provide a sortable to the store function.");return y.has(e)||y.set(e,new t),y.get(e)};function i(e,t,n){if(e instanceof Array)for(var r=0;r':t=document.createElement("div")),"string"==typeof n&&(r=t.classList).add.apply(r,n.split(" ")),t},L=function(e){if(!(e instanceof HTMLElement))throw new Error("You must provide a valid dom element");var n=window.getComputedStyle(e);return"border-box"===n.getPropertyValue("box-sizing")?parseInt(n.getPropertyValue("height"),10):["height","padding-top","padding-bottom"].map(function(e){var t=parseInt(n.getPropertyValue(e),10);return isNaN(t)?0:t}).reduce(function(e,t){return e+t})},x=function(e){if(!(e instanceof HTMLElement))throw new Error("You must provide a valid dom element");var n=window.getComputedStyle(e);return["width","padding-left","padding-right"].map(function(e){var t=parseInt(n.getPropertyValue(e),10);return isNaN(t)?0:t}).reduce(function(e,t){return e+t})},s=function(e,t){if(!(e instanceof Array))throw new Error("You must provide a Array of HTMLElements to be filtered.");return"string"!=typeof t?e:e.filter(function(e){return e.querySelector(t)instanceof HTMLElement||e.shadowRoot&&e.shadowRoot.querySelector(t)instanceof HTMLElement}).map(function(e){return e.querySelector(t)||e.shadowRoot&&e.shadowRoot.querySelector(t)})},p=function(e){return e.composedPath&&e.composedPath()[0]||e.target},m=function(e,t,n){return{element:e,posX:n.pageX-t.left,posY:n.pageY-t.top}},g=function(e,t,n){if(!(e instanceof Event))throw new Error("setDragImage requires a DragEvent as the first argument.");if(!(t instanceof HTMLElement))throw new Error("setDragImage requires the dragged element as the second argument.");if(n||(n=m),e.dataTransfer&&e.dataTransfer.setDragImage){var r=n(t,w(t),e);if(!(r.element instanceof HTMLElement)||"number"!=typeof r.posX||"number"!=typeof r.posY)throw new Error("The customDragImage function you provided must return and object with the properties element[string], posX[integer], posY[integer].");e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setData("text/plain",p(e).id),e.dataTransfer.setDragImage(r.element,r.posX,r.posY)}},M=function(e,t){if(!0===e.isSortable){var n=E(e).getConfig("acceptFrom");if(null!==n&&!1!==n&&"string"!=typeof n)throw new Error('HTML5Sortable: Wrong argument, "acceptFrom" must be "null", "false", or a valid selector string.');if(null!==n)return!1!==n&&0=parseInt(r.maxItems)&&H.parentElement!==n||(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=!0===E(n).getConfig("copy")?"copy":"move",o(n,t,e.pageX,e.pageY))}};i(t.concat(s),"dragover",r),i(t.concat(s),"dragenter",r)}),e)}return U.destroy=function(e){var t,n,r,o;n=c(t=e,"opts")||{},r=v(t.children,n.items),o=s(r,n.handle),a(t,"dragover"),a(t,"dragenter"),a(t,"dragstart"),a(t,"dragend"),a(t,"drop"),F(t),a(o,"mousedown"),h(r),q(r),W(S,P),t.isSortable=!1},U.enable=function(e){B(e)},U.disable=function(e){var t,n,r,o;n=c(t=e,"opts"),r=v(t.children,n.items),o=s(r,n.handle),l(t,"aria-dropeffect","none"),c(t,"_disabled","true"),l(o,"draggable","false"),a(o,"mousedown")},U.__testing={_data:c,_removeItemEvents:h,_removeItemData:q,_removeSortableData:F,_removeContainerEvents:W},U}(); 2 | //# sourceMappingURL=html5sortable.min.js.map 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pithy Screen Menu System for controlling Home Assistant 2 | 3 | **Created by: Milan Korenica** 4 | 5 | This is an ESPHome YAML script that implements a menu system to show state of and control several entities from Home Assistant on a Pithy Screen device. 6 | 7 | Pithy Screen is based on D1 mini, has a rotary encoder with push, a switch and SSD1306 screen over I2C. See more on [ioios website](https://ioios.io) and [their Github repo](https://github.com/ioios-io). 8 | 9 | Rotary encoder is used to browse the menu, push on the rotary is used to either enter submenu or enter setting. Side switch is used to return from setting or return to previous menu level. 10 | 11 | ## Setup 12 | 13 | There are two ways to setup the menu 14 | 1. Using config generator 15 | 2. Manual (recommended only if you want to heavily modify the config) 16 | 17 | ### Using config generator 18 | 19 | Config generator is in the [menu_generator](menu_generator) folder. The best way to use it is to clone/download the files to your computer and running from there. You can also use the [githack hosted version](https://rawcdn.githack.com/mikosoft83/pithy_screen_menu_system/a62acf32be99deb8db09b108542ffee5c1e66067/menu_generator/index.html). 20 | 21 | The menu generator __doesn't do any sanity checks__. You are in charge of filling in all the data correctly. __Every field of every item must be filled in__, the only __exceptions__ are Shortcuts in Screensaver section and the "Attribute" field in case of menu items that won't use it. If you manage to make a mistake you will only find out during compile or operation so be careful. Checks may be added in future versions. 22 | 23 | #### Loading existing config 24 | If you want to __load a previously generated YAML file__, click the Select config file button. It will read the file and if it finds any Home Assistant entities it will list all of them and ask to paste config from __template entities__ in the indicated format. The value template of these entities is expected to contain only ``state_attr`` function to report an attribute value. 25 | 26 | After that click Load config button and the config will be loaded. __Please be aware that it will only reliably load config files that are as they were generated.__ If you modified your config afterwards the config load may fail or yield unpredictable results. 27 | 28 | #### Creating new config 29 | First __choose your device type__, device name and friendly name. ESPHome and Home Assistant usually use the device name to connect to the device so it __needs to be unique__. Fill in the WiFi credentials. If you assembled the hardware yourself you can set the pins, otherwise leave as is. __If you are using non-Pithy hardware__ such as custom made device and need to change pins to values not present in dropdowns, you can modify them in the generated config under ``globals:`` section. 30 | 31 | __Screensaver shortcuts__ add possibility to trigger defined actions by pressing the dial or the button while on screensaver screen. 32 | 33 | __To set up the menu structure__ use the Menu section. You can __move the menu items__ around by dragging them by the large title. You can also __drag items out of submenu__ to another menu level or submenu. __Remember there needs to be at least one item in each submenu!__ Failing that will cause crashes when running on the ESP. 34 | 35 | __For each item__ you can use the preconfigured action on encoder change (the dropdown labeled "What to do on change") or you can type in your own code. The fields will expand when you click "Advanced settings". If you want to __modify one of the preconfigured actions__, first select the desired action in the dropdown and then select "Custom service call". After that you can edit the fields under "Advanced settings". 36 | 37 | Here are the possible menu item types and what they do: 38 | * 1: **Display value** - only show a value of a sensor, do nothing 39 | * 2: **Submenu** - if you press the encoder on this menu item, you will enter the submenu. Pressing the side button returns one level up. 40 | * 3: **Continuous setting** - set sensor that has a continuous range of values (such as thermostat, volume, blinds position etc.). Pressing the encoder will enter set mode and every turn of encoder will immediately change the value of the sensor. Pressing the encoder or side button will exist the set mode. This is best used with devices that can handle rapid value changes well, e.g. volume settings on a media player, color of a bulb, etc. _Not recommended for example for relay controlled blinds since the relay will be working too hard_. 41 | * 4: **Toggle** - change value of a binary sensor. Same as above but only has two states, ON or OFF. 42 | * 5: **Action button** - if you press the encoder on this menu item an action will be called. Can be any homeassistant service, script or automation. It's also possible to pass data (see [ESPHome docs on how to call HA services](https://esphome.io/components/api.html#homeassistant-service-action) ) 43 | * 6: **Continuous setting with confirmation** - same as continuous setting (number 3) but the value won't be changed on every encoder turn. To set the value encoder needs to be pressed again. Pushing the side button will exit set mode without setting the value. 44 | 45 | __If you need help with the meaning of each setting__ hover your mouse over each label. You'll get a tooltip with some (hopefully) useful information. 46 | 47 | Once you're happy with your menu click __Create config__. Two text fields will be populated, one with ESPHome YAML config and the other with Home Assistant template sensor config. 48 | 49 | You can download the YAML file with the __Download config file__ button. Compile and upload the YAML file using ESPHome and your preferred method. Don't forget to put the __font files__ from the repo in your ESPHome config folder (where the yaml file is) otherwise you'll get compilation errors. 50 | 51 | If any __template sensors for HA__ have been generated, paste that config into the respective config file in Home Assistant. This will be dependent on the structure of your yaml files and sensor configuration. The default is configuration.yaml and ``sensor:`` section like this: 52 | 53 | sensor: 54 | ... your sensors.. 55 | - platform: template 56 | sensors: 57 | pithy_.... 58 | value_template: ... 59 | ... 60 | 61 | ### Manual configuration 62 | 63 | __This section is not up to date. The basics of the menu structure are still true but some of the other details may work differently. To setup a config for the first time please use the config generator.__ 64 | 65 | Setup of menu structure and functions is done in several places: 66 | 1. Setup of menu structure and data 67 | 2. Setup of actual menu functions 68 | 3. Setup of template entities in Home Assistant 69 | 4. Import of entities from Home Assistant 70 | 71 | Each part of configuration is marked by comments like these: 72 | 73 | ##### 74 | ##### CONFIGURATION BLOCK HERE 75 | ##### 76 | 77 | ##### END OF CONFIGURATION BLOCK 78 | 79 | First block marks substitutions, where you need to specify board, name and respective pins for each function and data for menu system. 80 | Second block defines the menu structure and data and actions for each menu item 81 | Third and fourth blocks define sensors and binary sensors imported from Home Assistant. 82 | Let's look at each part in detail now. 83 | 84 | ### 1. Setup of menu structure and data 85 | 86 | The structure of the menu is stored in one dimensional array. Since menu is a tree, we need to be able to define how menu items are interconnected. For example, if we have menu structure like this: 87 | 88 | * Parent 1 89 | * Submenu 1-1 90 | * Submenu item 1-1-1 91 | * Submenu item 1-1-2 92 | * Submenu 1-2 93 | * Submenu item 1-2-1 94 | * Submenu item 1-2-2 95 | * Parent 2 96 | * Submenu 2-1 97 | * Submenu item 2-1-1 98 | * Submenu item 2-1-2 99 | * Submenu 2-2 100 | * Submenu item 2-2-1 101 | * Submenu item 2-2-2 102 | 103 | The structure would be stored in an array like this: 104 | 105 | Array index | Menu item 106 | 0 | Parent 1 107 | 1 | Parent 2 108 | 2 | Submenu 1-1 109 | 3 | Submenu 1-2 110 | 4 | Submenu item 1-1-1 111 | 5 | Submenu item 1-1-2 112 | 6 | Submenu item 1-2-1 113 | 7 | Submenu item 1-2-2 114 | 8 | Submenu 2-1 115 | 9 | Submenu 2-2 116 | 10 | Submenu item 2-1-1 117 | 11 | Submenu item 2-1-2 118 | 12 | Submenu item 2-2-1 119 | 13 | Submenu item 2-2-2 120 | 121 | Array index always starts with 0. 122 | 123 | But now we can see that if we go in order of the array we will actually not traverse the menu correctly. We need to define where each menu level starts and ends and how to go to submenu and return back. For this purpose we define a child for each submenu item and number of items in each submenu. So in our example, it would look like this: 124 | 125 | Array index | Menu item | Child item | Number of items in submenu 126 | 0 | Parent 1 | 2 | 2 127 | 1 | Parent 2 | 8 | 2 128 | 2 | Submenu 1-1 | 4 | 2 129 | 3 | Submenu 1-2 | 6 | 2 130 | 4 | Submenu item 1-1-1 | none | none 131 | 5 | Submenu item 1-1-2 | none | none 132 | 6 | Submenu item 1-2-1 | none | none 133 | 7 | Submenu item 1-2-2 | none | none 134 | 8 | Submenu 2-1 | 10 | 2 135 | 9 | Submenu 2-2 | 12 | 2 136 | 10 | Submenu item 2-1-1 | none | none 137 | 11 | Submenu item 2-1-2 | none | none 138 | 12 | Submenu item 2-2-1 | none | none 139 | 13 | Submenu item 2-2-2 | none | none 140 | 141 | And this is fundamentally how the menu is constructed. 142 | 143 | The menu structure is stored in four global arrays: 144 | * `menu_labels` - these are the texts that are displayed for each menu item 145 | * `menu_functions` - these define what each menu item does (will be explained in next chapter) 146 | * `menu_child` - for items, that are submenus, these point to the array index, where the first item of the submenu resides 147 | * `menu_length` - for submenus, these tell how many items are there in the submenu, for settings, these define the range of values (explained in chapter 3) 148 | 149 | And in two substitutions: 150 | * `menuDepth` - this defines how many levels the menu has including the top level 151 | * `menuSize` - this defines how many items there are (this is pretty much the last array index + 1) 152 | 153 | So our example menu would look like this: 154 | 155 | substitutions: 156 | menuDepth: '3' 157 | menuSize: '14' 158 | 159 | globals: 160 | - id: menu_labels 161 | type: char * [${menuSize}] 162 | initial_value: 'menu_labels = { "Parent 1", "Parent 2", "Submenu 1-1", ... , "Submenu item 2-2-2" }' 163 | 164 | And you can fill in the rest. 165 | 166 | In this code the menu item with index 0 is always screensaver, so you will actually need to account for that. See the example sctructure in the second configuration block in the YAML file. 167 | 168 | Also, the arrays in the example are formatted for readability like this: 169 | 170 | initial_value: ' 171 | { 172 | "Saver", "Menu 1", "Menu 2", 173 | "1st submenu 1", "1st submenu 2", 174 | "Continuous", "Binary", "Action button", 175 | "Cont+confirm", "Display", 176 | "2nd submenu 1", "2nd submenu 2" 177 | }' 178 | 179 | If you do this yourself, _don't forget comma_ after each element **but** the last one and don't forget that all array elements _need to be enclosed in curly braces_. 180 | 181 | ### 2. Setup of menu functions 182 | 183 | #### 2.1 Defining the functions 184 | 185 | So now that we have the structure of our menu, we want to define what each menu item does. There are several functions available that we can store in `menu_functions`: 186 | 187 | * 0: **Screensaver** (only valid for menu item 0) 188 | * 1: **Display value** - only show a value of a sensor, do nothing 189 | * 2: **Submenu** - if you press the encoder on this menu item, you will enter the submenu. Pressing the side button returns one level up. 190 | * 3: **Continuous setting** - set sensor that has a continuous range of values (such as thermostat, volume, blinds position etc.). Pressing the encoder will enter set mode and every turn of encoder will immediately change the value of the sensor. Pressing the encoder or side button will exist the set mode. This is best used with devices that can handle rapid value changes well, e.g. volume settings on a media player, color of a bulb, etc. _Not recommended for example for relay controlled blinds since the relay will be working too hard_. 191 | * 4: **Toggle** - change value of a binary sensor. Same as above but only has two states, ON or OFF. 192 | * 5: **Action button** - if you press the encoder on this menu item an action will be called. Can be any homeassistant service, script or automation. It's also possible to pass data (see [ESPHome docs on how to call HA services](https://esphome.io/components/api.html#homeassistant-service-action) ) 193 | * 6: **Continuous setting with confirmation** - same as continuous setting (number 3) but the value won't be changed on every encoder turn. To set the value encoder needs to be pressed again. Pushing the side button will exit set mode without setting the value. 194 | 195 | See the example in YAML file to see this in action. 196 | 197 | #### 2.2 Configuring the function calls 198 | 199 | Now that we have the functions stored we need to make sure ESPHome does something. For this there are three scripts defined that are called on appropriate places within the code. These three scripts are: 200 | * `menu_values` 201 | Contains only single lambda action that contains a single `switch()` statement. For each menu item that displays or sets a value of a sensor ensures the correct value is displayed. This value is assigned to the global variable `id(menu_current_value)`. Each case is the array index of the menu item for which we want to display the value. 202 | Here are premade `case` blocks for each menu function. Replace the # symbol with the array index of your menu item and *** with the name of your internal ESPhome sensor (explained in chapter 4): 203 | * For sensors with continuous values, use this `case` code: 204 | 205 | case #: id(menu_current_value) = id(***).state; break; 206 | 207 | * For binary sensors, the value needs to be converted to 0 or 1 like this: 208 | 209 | case #: id(menu_current_value) = id(***).state ? 1 : 0; break; 210 | 211 | * You also need to use one of the above for menu function "1: Display" depending on whether you're trying to display a binary or continuous sensor. 212 | 213 | * For item with continuous value with confirmation we need to account for set mode, so use this code: 214 | 215 | case #: id(menu_current_value) = id(menu_set_mode) ? #start + id(rotary_dial).state*#step : id(***).state; break; 216 | 217 | Note that there is a "#start" and "#step", these need to be replaced by actual values. These will be explained in chapter 2.3. 218 | 219 | **You need to put in as many of these `case` code blocks as many menu items displaying sensor values you have.** If you forget one or make a mistake you will see errorneous values displayed. 220 | 221 | * `menu_set_rotary` 222 | This is similar to the above script. Also contains only single lambda with `switch()` statement. This script sets the encoder to the value of the sensor when the encoder is pressed. As with previous script here are readymade `case` code blocks that you can use: 223 | * Continuous value sensors (use this for continuous with confirmation as well): 224 | 225 | case #: id(rotary_dial).set_value((id(***).state - #start)/#step); break; 226 | again, note the #step and #start. 227 | 228 | * Binary sensors: 229 | 230 | case #: id(rotary_dial).set_value(id(***).state ? 1 : 0); break; 231 | 232 | * `menu_actions` 233 | This is where the real magic happens. In this script you configure the Home Assistant calls for each menu item. Note these are not lambda calls since ESPHome doesn't support HA calls from lambda. So each menu item has its own `if` action with one lambda condition where you put your array index. 234 | Again, here are premade `if` actions for you to use: 235 | * Continuous sensor (also for continuous with confirmation): 236 | 237 | - if: 238 | condition: 239 | lambda: 'return id(menu_current_node) == #;' 240 | then: 241 | homeassistant.service: 242 | variables: 243 | x: 'return #start + id(rotary_dial).state*#step;' 244 | service: #service 245 | data_template: 246 | entity_id: #entity 247 | value: '{{ x }}' 248 | 249 | Configuration of the `data_template` key will depend on which service you call. However to pass the value to the sensor always use `'{{ x }}'` (do not forget the single quotes). See YAML for examples with real HA services. 250 | 251 | * Binary sensor: 252 | 253 | - if: 254 | condition: 255 | lambda: 'return id(menu_current_node) == #;' 256 | then: 257 | if: 258 | condition: 259 | lambda: 'return id(rotary_dial).state;' 260 | then: 261 | homeassistant.service: 262 | service: switch.turn_on 263 | data: 264 | entity_id: #entity 265 | else: 266 | homeassistant.service: 267 | service: switch.turn_off 268 | data: 269 | entity_id: #entity 270 | 271 | Here's an example with switch. If you need to triger something else just replace the service calls in the appropriate places (`then` block for "ON" state, `else` block for "OFF" state). 272 | **Note**: It's not a good idea to use `switch.toggle` or similar services that toggle a state in this block. The behavior will seem erratic. Use "5: Action button" for that. 273 | 274 | * Action button: 275 | We didn't define anything for action button in previous scripts because the Action button menu function doesn't call those. But it will call this script so it needs to be here: 276 | 277 | - if: 278 | condition: 279 | lambda: 'return id(menu_current_node) == #;' 280 | then: 281 | homeassistant.service: 282 | service: script.example_script 283 | data: 284 | example: data 285 | 286 | Just a simple HA service call. 287 | 288 | #### 2.3 Mapping the continuous sensor values 289 | 290 | The internal rotary encoder range always starts at 0 but some sensors and service calls will require values from range that start on non-zero value. For example, a thermostat setting may be in a range of 16 to 25 degree Celsius. Furthermore, the encoder always increments by 1 but the value step may be different, in our thermostat example, the step may be 0.5 degree. 291 | 292 | So to properly map the encoder to the sensor value we need to calculate the range for each sensor/service call first: 293 | `range = (stop - start) / step` 294 | where start and stop are the first and last value in the sensor range and step is the minimum step (difference between two closest values) 295 | In our temperature example the range would be `(25 - 16)/0.5 = 18` 296 | 297 | This `range` value is the one you put into `menu_length` array for each menu item that uses continuous sensor (so both continuous and continuous with confirmation). If you forget to put in the correct value the settings won't cover the whole range of the sensor. 298 | 299 | The start and step values then need to be used in the scripts above in place of `#start` and `#step` placeholders. 300 | 301 | Please keep in mind this calculation is valid for sensors/service calls with linear range. If the sensor/service uses a different maping (logarithmic, exponential or anything else) you'll need to figure out the correct mapping and code yourself. 302 | 303 | ### 3. Setup of template entities in Home Assistant 304 | 305 | Since ESPHome doesn't support importing entity attributes from Home Assistant entities you need to configure template entities in HA for each attribute that you want to display or control using this menu system. Note that if the value that you want to show/control is in the state of the entity, you don't need to configure a template entity for that, you can import it directly to ESPHome (see next chapter on how to do that). 306 | 307 | So in your Home Assistant _configuration.yaml_ (or relevant yaml file if you use split config) put this code for each entity attribute you want to show/control: 308 | 309 | sensor: 310 | - platform: template 311 | sensors: 312 | sensor_1: 313 | value_template: "{{ state_attr('some.entity', 'attribute') }}" 314 | sensor_2: 315 | value_template: "{{ state_attr('other.entity', 'different_attribute') }}" 316 | 317 | This will create two new sensors named `sensor.sensor_1` and `sensor.sensor_2`. These are now ready to be imported to ESPHome. 318 | 319 | ### 4. Import of entities from Home Assistant 320 | 321 | To use a value of HA entity in ESPHome you need to import it to an internal ESPHome sensor. Here's an example: 322 | 323 | sensor: 324 | - platform: homeassistant 325 | name: "Example sensor" 326 | entity_id: sensor.example_sensor 327 | id: ex_cont 328 | internal: true 329 | on_value: 330 | then: 331 | # Logic to correctly update menu values 332 | - script.execute: menu_values 333 | - if: 334 | condition: 335 | lambda: 'return id(menu_set_mode);' 336 | then: 337 | - script.execute: menu_set_rotary 338 | # End of menu values logic 339 | 340 | `entity_id` contains the name of the HA sensor you want to import. `id` contains a name that you can pick and it will be internal to ESPHome. You need to use this sensor `id` in the three scripts configured in chapter 2.2 in place of the `***` placeholder. 341 | 342 | Note that the sensor has `internal: true` configured, so that it doesn't show in Home Assistant. Also the `on_value:` block needs to contain the two `script.execute` and `if` calls to properly update values in the menu system when the state of the sensor changes. If you accidentaly delete the `on_value:` block the menu system may display or set wrong values when used. 343 | 344 | The sensors can be imported in the third (for continuous sensors) and fourth (for binary sensors) configuration block (see the introductory chapter about the configuration blocks). 345 | 346 | ## Final remarks 347 | 348 | It's probably a good idea to first prepare the whole menu on a piece of paper together with array indices, menu functions, ranges, associated sensors etc. Once you start putting it into code it's quite difficult to make changes. If you need to insert a menu item somewhere in the middle of the array all the indices that follow will shift and you need to rewrite all the indices in the three srevice calls from chapter 2.2 accordingly. 349 | 350 | That is it, if you reached this far you should have successfully configured the menu system for use with your chosen sensors. Have fun! 351 | -------------------------------------------------------------------------------- /menu_generator/pithy_screen_milan_example.yaml: -------------------------------------------------------------------------------- 1 | ### Pithy Screen Menu System for controlling Home Assistant 2 | ### 3 | ### Created by: Milan Korenica 4 | ### Licensed under GNU General Public License v3.0 5 | 6 | esphome: 7 | name: ${unitName} 8 | platform: ${boardPlatform} 9 | board: ${boardName} 10 | #set default for rotary 11 | on_boot: 12 | priority: 250 13 | then: 14 | - sensor.rotary_encoder.set_value: 15 | id: rotary_dial 16 | value: 0 17 | - binary_sensor.template.publish: 18 | id: api_connected 19 | state: OFF 20 | - wait_until: 21 | api.connected 22 | - sensor.rotary_encoder.set_value: 23 | id: rotary_dial 24 | value: 0 25 | - binary_sensor.template.publish: 26 | id: api_connected 27 | state: ON 28 | 29 | wifi: 30 | ssid: fake 31 | password: fake 32 | 33 | # Enable fallback hotspot (captive portal) in case wifi connection fails 34 | ap: 35 | ssid: "pithy" 36 | password: "pithypithy" 37 | 38 | captive_portal: 39 | 40 | # Enable logging 41 | logger: 42 | 43 | # Enable Home Assistant API 44 | api: 45 | password: fake 46 | 47 | ota: 48 | password: fake 49 | 50 | ##### 51 | ##### CONFIGURATION BLOCK HERE 52 | ##### 53 | substitutions: 54 | boardPlatform: ESP8266 55 | boardName: d1_mini 56 | unitName: pithy_screen_milan 57 | friendlyName: Pithy Screen test 58 | 59 | encoderPinA: D5 60 | encoderPinB: D6 61 | encoderSwitch: D7 62 | i2cData: D1 63 | i2cClock: D2 64 | pir: D0 65 | button: TX 66 | 67 | # Menu system 68 | menuDepth: '2' 69 | menuSize: '17' 70 | 71 | ##### END OF CONFIGURATION BLOCK 72 | 73 | globals: 74 | # Screensaver 75 | - id: ss_x 76 | type: signed char 77 | initial_value: '0' 78 | 79 | - id: ss_y 80 | type: signed char 81 | initial_value: '8' 82 | 83 | - id: ss_vx 84 | type: signed char 85 | initial_value: '1' 86 | 87 | - id: ss_vy 88 | type: signed char 89 | initial_value: '1' 90 | 91 | - id: wi 92 | type: unsigned char 93 | initial_value: '0' 94 | 95 | # Blank screen 96 | - id: s_blank 97 | type: bool 98 | initial_value: 'false' 99 | 100 | # Menu helpers 101 | 102 | - id: menu_max_level 103 | type: unsigned char 104 | initial_value: '${menuDepth}' 105 | 106 | - id: menu_level 107 | type: unsigned char 108 | 109 | - id: menu_position 110 | type: unsigned char[${menuDepth}] 111 | 112 | - id: menu_parent 113 | type: unsigned char[${menuDepth}] 114 | 115 | - id: menu_current_node 116 | type: unsigned char 117 | 118 | - id: menu_current_label 119 | type: char * 120 | 121 | - id: menu_current_value 122 | type: float 123 | 124 | - id: menu_set_mode 125 | type: bool 126 | initial_value: 'false' 127 | 128 | ##### 129 | ##### CONFIGURATION BLOCK HERE 130 | ##### 131 | 132 | # Set these to labels you want to display 133 | - id: menu_labels 134 | type: char * [${menuSize}] 135 | initial_value: '{"Saver","Sonos","Blinds","LIDL Plug","Temperature","Humidity","Balcony temp","Balcony hum","Volume","Play/Pause","Antiglare","Position","Open","Close","Half tilt","Tilt close","Tilt open"}' 136 | 137 | # Set these to functions of particular menu items 138 | - id: menu_functions 139 | type: unsigned char[${menuSize}] 140 | initial_value: '{0,2,2,4,1,1,1,1,3,5,5,6,5,5,5,5,5}' 141 | 142 | # For submenu items, what are the children? 143 | - id: menu_child 144 | type: unsigned char[${menuSize}] 145 | initial_value: '{0,8,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0}' 146 | 147 | # How many items are there for each submenu? For continuous settings, what is the range? 148 | - id: menu_length 149 | type: unsigned char[${menuSize}] 150 | initial_value: '{8,2,7,0,0,0,0,0,100,0,0,100,0,0,0,0,0}' 151 | 152 | script: 153 | # What value to display for each menu item 154 | - id: menu_values 155 | then: 156 | - lambda: |- 157 | switch(id(menu_current_node)) { 158 | case 3: id(menu_current_value) = id(switch_lidl_plug_kitchen).state ? 1 : 0; break; 159 | 160 | case 4: id(menu_current_value) = id(${unitName}_temperature).state; break; 161 | 162 | case 5: id(menu_current_value) = id(${unitName}_humidity).state; break; 163 | 164 | case 6: id(menu_current_value) = id(sensor_balcony_th_temperature).state; break; 165 | 166 | case 7: id(menu_current_value) = id(sensor_balcony_th_humidity).state; break; 167 | 168 | case 8: id(menu_current_value) = id(media_player_kitchen_volume_level).state * 100; break; 169 | 170 | case 11: id(menu_current_value) = id(menu_set_mode) ? id(rotary_dial).state : id(cover_shelly_25_blinds_office_roller_0_current_position).state; break; 171 | //case 11: id(menu_current_value) = id(cover_shelly_25_blinds_office_roller_0_current_position).state; break; 172 | 173 | 174 | } 175 | 176 | # What value to set rotary encoder to for each menu item setting 177 | - id: menu_set_rotary 178 | then: 179 | - lambda: |- 180 | switch(id(menu_current_node)) { 181 | case 3: id(rotary_dial).set_value(id(switch_lidl_plug_kitchen).state ? 1 : 0); break; 182 | 183 | case 8: id(rotary_dial).set_value(round((id(media_player_kitchen_volume_level).state)/0.01)); break; 184 | 185 | case 11: id(rotary_dial).set_value(round(id(cover_shelly_25_blinds_office_roller_0_current_position).state)); break; 186 | 187 | 188 | } 189 | 190 | # Actions for each menu item setting 191 | - id: menu_actions 192 | then: 193 | - if: 194 | condition: 195 | lambda: 'return id(menu_current_node) == 3;' 196 | then: 197 | if: 198 | condition: 199 | lambda: 'return id(rotary_dial).state;' 200 | then: 201 | homeassistant.service: 202 | service: switch.turn_on 203 | data: 204 | entity_id: switch.lidl_plug_kitchen 205 | else: 206 | homeassistant.service: 207 | service: switch.turn_off 208 | data: 209 | entity_id: switch.lidl_plug_kitchen 210 | 211 | - if: 212 | condition: 213 | lambda: 'return id(menu_current_node) == 8;' 214 | then: 215 | homeassistant.service: 216 | variables: 217 | x: 'return id(rotary_dial).state*0.01;' 218 | service: media_player.volume_set 219 | data_template: 220 | entity_id: media_player.kitchen 221 | volume_level: '{{ x }}' 222 | 223 | - if: 224 | condition: 225 | lambda: 'return id(menu_current_node) == 9;' 226 | then: 227 | homeassistant.service: 228 | service: media_player.media_play_pause 229 | data: 230 | entity_id: media_player.kitchen 231 | 232 | - if: 233 | condition: 234 | lambda: 'return id(menu_current_node) == 10;' 235 | then: 236 | homeassistant.service: 237 | service: script.blinds_antiglare 238 | data: 239 | entity: cover.shelly_25_blinds_office_roller_0 240 | 241 | - if: 242 | condition: 243 | lambda: 'return id(menu_current_node) == 11;' 244 | then: 245 | homeassistant.service: 246 | variables: 247 | x: 'return id(rotary_dial).state;' 248 | service: cover.set_cover_position 249 | data_template: 250 | entity_id: cover.shelly_25_blinds_office_roller_0 251 | position: '{{ x }}' 252 | 253 | - if: 254 | condition: 255 | lambda: 'return id(menu_current_node) == 12;' 256 | then: 257 | homeassistant.service: 258 | service: cover.open_cover 259 | data: 260 | entity_id: cover.shelly_25_blinds_office_roller_0 261 | 262 | - if: 263 | condition: 264 | lambda: 'return id(menu_current_node) == 13;' 265 | then: 266 | homeassistant.service: 267 | service: cover.close_cover 268 | data: 269 | entity_id: cover.shelly_25_blinds_office_roller_0 270 | 271 | - if: 272 | condition: 273 | lambda: 'return id(menu_current_node) == 14;' 274 | then: 275 | homeassistant.service: 276 | service: script.blinds_half_tilt 277 | data: 278 | entity: cover.shelly_25_blinds_office_roller_0 279 | 280 | - if: 281 | condition: 282 | lambda: 'return id(menu_current_node) == 15;' 283 | then: 284 | homeassistant.service: 285 | service: script.blinds_tilt_close 286 | data: 287 | entity: cover.shelly_25_blinds_office_roller_0 288 | 289 | - if: 290 | condition: 291 | lambda: 'return id(menu_current_node) == 16;' 292 | then: 293 | homeassistant.service: 294 | service: script.blinds_tilt_open 295 | data: 296 | entity: cover.shelly_25_blinds_office_roller_0 297 | 298 | 299 | 300 | # Action when dial is pressed on screensaver screen 301 | - id: dial_ss_press 302 | then: 303 | homeassistant.service: 304 | service: media_player.media_play_pause 305 | data: 306 | entity_id: media_player.kitchen 307 | 308 | 309 | # Action when button is pressed on screensaver screen 310 | - id: button_1_ss_press 311 | then: 312 | homeassistant.service: 313 | service: script.blinds_antiglare 314 | data: 315 | entity: cover.shelly_25_blinds_office_roller_0 316 | 317 | 318 | ##### END OF CONFIGURATION BLOCK 319 | 320 | - id: ss_timeout 321 | mode: restart 322 | then: 323 | - delay: 1min 324 | - lambda: >- 325 | id(menu_level) = 0; 326 | id(menu_position)[0] = 0; 327 | id(menu_parent)[0] = 0; 328 | id(menu_current_node) = 0; 329 | id(menu_set_mode) = false; 330 | id(rotary_dial).set_value(0); 331 | 332 | - id: s_blankout 333 | mode: restart 334 | then: 335 | - if: 336 | condition: 337 | binary_sensor.is_on: ${unitName}_motion 338 | then: 339 | lambda: 'id(s_blank) = false;' 340 | else: 341 | - delay: 10s 342 | - lambda: 'id(s_blank) = true;' 343 | 344 | interval: 345 | # Screen saver logic & wait indicator 346 | - interval: 0.2s 347 | then: 348 | - lambda: |- 349 | id(ss_x) += id(ss_vx); 350 | id(ss_y) += id(ss_vy); 351 | if(id(ss_x)>45 || id(ss_x)<1) id(ss_vx) *= -1; 352 | if(id(ss_y)>29 || id(ss_y)<6) id(ss_vy) *= -1; 353 | id(wi) = ++id(wi) > 15 ? 0 : id(wi); // wait indicator logic 354 | 355 | i2c: 356 | sda: ${i2cData} 357 | scl: ${i2cClock} 358 | frequency: 200kHz 359 | scan: True 360 | id: bus_a 361 | 362 | time: 363 | - platform: homeassistant 364 | id: ha_time 365 | 366 | font: 367 | - file: "OpenSans-Regular.ttf" 368 | id: big_font 369 | size: 31 370 | glyphs: ":0123456789" 371 | 372 | - file: "OpenSans-Light.ttf" 373 | id: small_font 374 | size: 19 375 | glyphs: ">-:/&!°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ." 376 | 377 | - file: "OpenSans-Light.ttf" 378 | id: tiny_font 379 | size: 12 380 | glyphs: ":0123456789Conectig." 381 | 382 | display: 383 | - platform: ssd1306_i2c 384 | model: "SH1106 128x64" 385 | address: 0x3C 386 | update_interval: 0.1s 387 | id: idisplay 388 | lambda: |- 389 | 390 | if (!id(api_connected).state){ 391 | // Little animation before API is online 392 | // if (!id(s_con)) { 393 | // it.printf(64, 0, id(tiny_font), TextAlign::TOP_CENTER, "Connecting..."); 394 | // id(s_con) = true; 395 | // } 396 | // it.filled_circle(64, 40, 20); 397 | // it.filled_circle(64, 40, 15, COLOR_OFF); 398 | // unsigned char wii = floor(id(wi)/2); 399 | // if(wii > 0 && wii < 5) it.filled_rectangle(65, 20, 20, 21, COLOR_OFF); 400 | // if(wii > 1 && wii < 6) it.filled_rectangle(65, 40, 20, 21, COLOR_OFF); 401 | // if(wii > 2 && wii < 7) it.filled_rectangle(44, 40, 21, 21, COLOR_OFF); 402 | // if(wii > 3 && wii < 8) it.filled_rectangle(44, 20, 21, 21, COLOR_OFF); 403 | // int k=floor(id(wi)/2); 404 | it.line(56, 32, 56+id(wi), 32); 405 | } else { 406 | 407 | // Blank screen if PIR off 408 | if (id(s_blank)) { return; } 409 | 410 | // Screensaver is always node 0 411 | if(id(menu_current_node)==0) { 412 | 413 | // Bouncy time 414 | it.strftime(id(ss_x), id(ss_y), id(big_font), "%H:%M", id(ha_time).now()); 415 | } 416 | else { 417 | 418 | // Header time 419 | it.strftime(0, 6, id(tiny_font), COLOR_ON, TextAlign::CENTER_LEFT, "%H:%M", id(ha_time).now()); 420 | // Header wifi 421 | for(int i=0; i<5; i++) if(i0){ 424 | 425 | // y-ccord start of the level display 426 | int b = 64 - (4 * id(menu_level)); 427 | for(int i=0; i" : "" ); 458 | 459 | // Show value 460 | if(id(menu_set_mode)) { 461 | 462 | switch(id(menu_functions)[id(menu_current_node)]){ 463 | 464 | case 3: 465 | case 6: 466 | // Value 467 | it.printf(127, 12, id(small_font), TextAlign::TOP_RIGHT, "%.2f", id(menu_current_value)); 468 | // Setting progressbar, outline rectangle 469 | it.rectangle(0, 20, 54, 12); 470 | // Inner fill 471 | it.filled_rectangle(2, 22, round(id(rotary_dial).state*0.50), 8); 472 | break; 473 | case 4: 474 | // Labels 475 | it.printf(42, 12, id(small_font), TextAlign::TOP_RIGHT, "Off"); 476 | it.printf(86, 12, id(small_font), TextAlign::TOP_LEFT, "On"); 477 | // Switch, outline rectangle 478 | it.rectangle(52, 20, 24, 12); 479 | // Inner toggle 480 | it.filled_rectangle(54 + id(rotary_dial).state*10, 22, 10, 8); 481 | 482 | } 483 | 484 | } else { 485 | 486 | // Show value only if Display or Setting 487 | switch(id(menu_functions)[id(menu_current_node)]){ 488 | 489 | case 1: 490 | case 3: 491 | case 6: 492 | it.printf(64, 12, id(small_font), TextAlign::TOP_CENTER, "%.2f", id(menu_current_value)); 493 | break; 494 | case 4: 495 | case 7: 496 | it.printf(64, 12, id(small_font), TextAlign::TOP_CENTER, "%s", id(menu_current_value) == 0 ? "Off" : "On"); 497 | break; 498 | case 5: // show button 499 | it.rectangle(52, 19, 24, 14); 500 | if(id(rotary_dial_push).state == 0){ 501 | // horizontal shades 502 | it.line(53, 20, 73, 20); 503 | it.line(54, 31, 72, 31); 504 | // vertical shades 505 | it.line(53, 20, 53, 30); 506 | it.line(74, 21, 74, 29); 507 | 508 | } 509 | break; 510 | 511 | } 512 | } 513 | } 514 | 515 | } 516 | 517 | sensor: 518 | - platform: rotary_encoder 519 | id: rotary_dial 520 | pin_a: 521 | number: ${encoderPinA} 522 | inverted: true 523 | mode: INPUT_PULLUP 524 | pin_b: 525 | number: ${encoderPinB} 526 | inverted: true 527 | mode: INPUT_PULLUP 528 | filters: 529 | - lambda: |- 530 | unsigned char a; 531 | if(id(menu_set_mode)) { //if set mode, rotary should go from 0 to according setting 532 | 533 | switch(id(menu_functions)[id(menu_current_node)]){ 534 | case 3: 535 | case 6: 536 | a = id(menu_length)[id(menu_current_node)] + 1; break; // continuous 537 | case 4: a = 2; break; // binary 538 | } 539 | 540 | } else { //if not, it should go to level length 541 | 542 | //get current menu length 543 | a = id(menu_length)[id(menu_parent)[id(menu_level)]]; 544 | 545 | } 546 | 547 | //if rotary is over length, set to length 548 | if(x >= a) { 549 | 550 | id(rotary_dial).set_value(a-1); 551 | return a-1; 552 | 553 | } 554 | else return x; 555 | - debounce: 0.02s 556 | resolution: 1 557 | min_value: 0 558 | on_value: 559 | then: 560 | - if: 561 | condition: 562 | api.connected 563 | then: 564 | - if: 565 | condition: 566 | # Are we setting or browsing? 567 | lambda: 'return id(menu_set_mode);' 568 | then: 569 | # Change setting only if not in continuous + confirm 570 | - if: 571 | condition: 572 | lambda: 'return !(id(menu_functions)[id(menu_current_node)] == 6);' 573 | then: 574 | - script.execute: menu_actions 575 | else: 576 | # Browsing mode, set menu position 577 | - lambda: |- 578 | //set current node to start of current child + rotary position 579 | id(menu_current_node) = id(menu_child)[id(menu_parent)[id(menu_level)]] + x; 580 | //set current level position 581 | id(menu_position)[id(menu_level)] = x; 582 | # Update value 583 | - script.execute: menu_values 584 | - script.execute: ss_timeout 585 | - platform: wifi_signal 586 | id: wifisignal 587 | update_interval: 20s 588 | 589 | - platform: template 590 | id: wifistep 591 | update_interval: 20s 592 | lambda: |- 593 | if(isnan(id(wifisignal).state)) return 0; 594 | else return round((id(wifisignal).state+100)/10); 595 | 596 | - platform: sht3xd 597 | temperature: 598 | name: "${friendlyName} Temperature" 599 | id: ${unitName}_temperature 600 | filters: 601 | - offset: -4 602 | on_value: 603 | then: 604 | # Logic to correctly update menu values 605 | - script.execute: menu_values 606 | # End of menu values logic 607 | humidity: 608 | name: "${friendlyName} Humidity" 609 | id: ${unitName}_humidity 610 | on_value: 611 | then: 612 | # Logic to correctly update menu values 613 | - script.execute: menu_values 614 | # End of menu values logic 615 | address: 0x44 616 | update_interval: 15s 617 | 618 | ##### 619 | ##### CONFIGURATION BLOCK HERE 620 | ##### 621 | 622 | # Sensors from Home Assistant 623 | 624 | - platform: homeassistant 625 | name: "HA sensor sensor.balcony_th_temperature" 626 | entity_id: sensor.balcony_th_temperature 627 | id: sensor_balcony_th_temperature 628 | internal: true 629 | on_value: 630 | then: 631 | # Logic to correctly update menu values 632 | - script.execute: menu_values 633 | - if: 634 | condition: 635 | lambda: 'return id(menu_set_mode);' 636 | then: 637 | - script.execute: menu_set_rotary 638 | # End of menu values logic 639 | 640 | - platform: homeassistant 641 | name: "HA sensor sensor.balcony_th_humidity" 642 | entity_id: sensor.balcony_th_humidity 643 | id: sensor_balcony_th_humidity 644 | internal: true 645 | on_value: 646 | then: 647 | # Logic to correctly update menu values 648 | - script.execute: menu_values 649 | - if: 650 | condition: 651 | lambda: 'return id(menu_set_mode);' 652 | then: 653 | - script.execute: menu_set_rotary 654 | # End of menu values logic 655 | 656 | - platform: homeassistant 657 | name: "HA sensor sensor.pithy_media_player_kitchen_volume_level" 658 | entity_id: sensor.pithy_media_player_kitchen_volume_level 659 | id: media_player_kitchen_volume_level 660 | internal: true 661 | on_value: 662 | then: 663 | # Logic to correctly update menu values 664 | - script.execute: menu_values 665 | - if: 666 | condition: 667 | lambda: 'return id(menu_set_mode);' 668 | then: 669 | - script.execute: menu_set_rotary 670 | # End of menu values logic 671 | 672 | - platform: homeassistant 673 | name: "HA sensor sensor.pithy_cover_shelly_25_blinds_office_roller_0_current_position" 674 | entity_id: sensor.pithy_cover_shelly_25_blinds_office_roller_0_current_position 675 | id: cover_shelly_25_blinds_office_roller_0_current_position 676 | internal: true 677 | on_value: 678 | then: 679 | # Logic to correctly update menu values 680 | - script.execute: menu_values 681 | - if: 682 | condition: 683 | lambda: 'return id(menu_set_mode);' 684 | then: 685 | - script.execute: menu_set_rotary 686 | # End of menu values logic 687 | 688 | 689 | ##### END OF CONFIGURATION BLOCK 690 | 691 | binary_sensor: 692 | - platform: gpio 693 | id: rotary_dial_push 694 | pin: 695 | number: ${encoderSwitch} 696 | inverted: true 697 | mode: INPUT_PULLUP 698 | on_press: 699 | then: 700 | - if: 701 | condition: 702 | api.connected 703 | then: 704 | # Execute screensaver action 705 | - if: 706 | condition: 707 | lambda: 'return id(menu_current_node) == 0;' 708 | then: 709 | script.execute: dial_ss_press 710 | 711 | - if: 712 | condition: 713 | # Execute continuous setting with confirmation when returning from set mode 714 | lambda: 'return id(menu_functions)[id(menu_current_node)] == 6 && id(menu_set_mode) == true;' 715 | then: 716 | - script.execute: menu_actions 717 | 718 | - if: 719 | condition: 720 | # Set mode for continuous or binary setting 721 | lambda: 'return (id(menu_functions)[id(menu_current_node)] == 3 || id(menu_functions)[id(menu_current_node)] == 4 || id(menu_functions)[id(menu_current_node)] == 6);' 722 | then: 723 | - lambda: |- 724 | //toggle set mode 725 | if(id(menu_set_mode)) { 726 | 727 | id(menu_set_mode) = false; 728 | // restore rotary value to position 729 | id(rotary_dial).set_value(id(menu_position)[id(menu_level)]); 730 | 731 | } else id(menu_set_mode) = true; 732 | 733 | - if: 734 | condition: 735 | # Button action 736 | lambda: 'return id(menu_functions)[id(menu_current_node)] == 5;' 737 | then: 738 | - script.execute: menu_actions 739 | 740 | # If set mode, set rotary 741 | - if: 742 | condition: 743 | lambda: 'return id(menu_set_mode);' 744 | then: 745 | - script.execute: menu_set_rotary 746 | 747 | - if: 748 | condition: 749 | # Go to submenu. This needs to be last to prevent setting new item and also executing it 750 | lambda: 'return id(menu_functions)[id(menu_current_node)] == 2;' 751 | then: 752 | - lambda: |- 753 | //raise level up to max level 754 | id(menu_level) = ++id(menu_level) > id(menu_max_level) ? id(menu_max_level) : id(menu_level); 755 | //set parent node for new level 756 | id(menu_parent)[id(menu_level)] = id(menu_current_node); 757 | //set new current node 758 | id(menu_current_node) = id(menu_child)[id(menu_parent)[id(menu_level)]]; 759 | //reset rotary to 0 760 | id(rotary_dial).set_value(0); 761 | //reset position in current level to 0 762 | id(menu_position)[id(menu_level)] = 0; 763 | 764 | # Display entities value for each menu item 765 | - script.execute: menu_values 766 | - script.execute: ss_timeout 767 | 768 | - platform: gpio 769 | pin: ${pir} 770 | id: ${unitName}_motion 771 | name: "${friendlyName} Motion" 772 | device_class: motion 773 | on_state: 774 | then: 775 | # Logic to correctly update menu values 776 | - script.execute: menu_values 777 | # End of menu values logic 778 | 779 | # BLank screen if motion not detected 780 | - script.execute: s_blankout 781 | 782 | - platform: gpio 783 | id: button_1 784 | pin: 785 | number: ${button} 786 | inverted: true 787 | mode: INPUT_PULLUP 788 | on_press: 789 | then: 790 | # Execute screensaver action 791 | - if: 792 | condition: 793 | and: 794 | - lambda: 'return id(menu_current_node) == 0;' 795 | - api.connected 796 | then: 797 | script.execute: button_1_ss_press 798 | 799 | - lambda: |- 800 | if(id(menu_set_mode)) { 801 | 802 | id(menu_set_mode) = false; 803 | id(rotary_dial).set_value(id(menu_position)[id(menu_level)]); 804 | } 805 | else { 806 | 807 | if(id(menu_level) > 0) { //if we have anywhere to return 808 | 809 | //set new current node to current parent 810 | id(menu_current_node) = id(menu_parent)[id(menu_level)]; 811 | //return to previous level 812 | --id(menu_level); 813 | //reset rotary to position for current level 814 | id(rotary_dial).set_value(id(menu_position)[id(menu_level)]); 815 | } else { 816 | 817 | if(id(menu_level) == 0) { //if we are at level 0, jump to saver 818 | 819 | //set new current node to 0 820 | id(menu_current_node) = 0; 821 | //reset rotary to 0 822 | id(rotary_dial).set_value(0); 823 | //reset menu position for current level to 0 824 | id(menu_position)[id(menu_level)] = 0; 825 | } } } 826 | 827 | - script.execute: ss_timeout 828 | 829 | - platform: template 830 | id: api_connected 831 | 832 | ##### 833 | ##### CONFIGURATION BLOCK HERE 834 | ##### 835 | 836 | # Binary sensors from HomeAssistant 837 | - platform: homeassistant 838 | name: "HA sensor switch.lidl_plug_kitchen" 839 | entity_id: switch.lidl_plug_kitchen 840 | id: switch_lidl_plug_kitchen 841 | internal: true 842 | on_state: 843 | then: 844 | # Logic to correctly update menu values 845 | - script.execute: menu_values 846 | - if: 847 | condition: 848 | lambda: 'return id(menu_set_mode);' 849 | then: 850 | - script.execute: menu_set_rotary 851 | # End of menu values logic 852 | 853 | 854 | ##### END OF CONFIGURATION BLOCK -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /menu_generator/js-yaml.min.js: -------------------------------------------------------------------------------- 1 | /*! js-yaml 3.14.1 https://github.com/nodeca/js-yaml */!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).jsyaml=e()}(function(){return function i(r,o,a){function s(t,e){if(!o[t]){if(!r[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=o[t]={exports:{}},r[t][0].call(n.exports,function(e){return s(r[t][1][e]||e)},n,n.exports,i,r,o,a)}return o[t].exports}for(var c="function"==typeof require&&require,e=0;e=i.flowLevel;switch(V(r,n,i.indent,t,function(e){return function(e,t){for(var n=0,i=e.implicitTypes.length;n"+z(r,i.indent)+J(U(function(t,n){var e,i=/(\n+)([^\n]*)/g,r=function(){var e=-1!==(e=t.indexOf("\n"))?e:t.length;return i.lastIndex=e,Q(t.slice(0,e),n)}(),o="\n"===t[0]||" "===t[0];for(;e=i.exec(t);){var a=e[1],s=e[2];e=" "===s[0],r+=a+(o||e||""===s?"":"\n")+Q(s,n),o=e}return r}(r,t),e));case G:return'"'+function(e){for(var t,n,i,r="",o=0;ot&&o tag resolver accepts not "'+o+'" style');i=r.represent[o](t,o)}e.dump=i}return 1}}function ee(e,t,n,i,r,o){e.tag=null,e.dump=n,X(e,n,!1)||X(e,n,!0);var a=l.call(e.dump);i=i&&(e.flowLevel<0||e.flowLevel>t);var s,c,u="[object Object]"===a||"[object Array]"===a;if(u&&(c=-1!==(s=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||c||2!==e.indent&&0 "+e.dump)}return 1}function te(e,t){var n,i,r=[],o=[];for(!function e(t,n,i){var r,o,a;if(null!==t&&"object"==typeof t)if(-1!==(o=n.indexOf(t)))-1===i.indexOf(o)&&i.push(o);else if(n.push(t),Array.isArray(t))for(o=0,a=t.length;o>10),56320+(c-65536&1023)),e.position++}else N(e,"unknown escape sequence");n=i=e.position}else S(u)?(L(e,n,i,!0),B(e,Y(e,!1,t)),n=i=e.position):e.position===e.lineStart&&R(e)?N(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}N(e,"unexpected end of the stream within a double quoted scalar")}}function K(e,t){var n,i,r=e.tag,o=e.anchor,a=[],s=!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),i=e.input.charCodeAt(e.position);0!==i&&45===i&&O(e.input.charCodeAt(e.position+1));)if(s=!0,e.position++,Y(e,!0,-1)&&e.lineIndent<=t)a.push(null),i=e.input.charCodeAt(e.position);else if(n=e.line,P(e,t,x,!1,!0),a.push(e.result),Y(e,!0,-1),i=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==i)N(e,"bad indentation of a sequence entry");else if(e.lineIndentt?p=1:e.lineIndent===t?p=0:e.lineIndentt?p=1:e.lineIndent===t?p=0:e.lineIndentt)&&(P(e,t,A,!0,r)&&(m?d=e.result:h=e.result),m||(U(e,l,p,f,d,h,o,a),f=d=h=null),Y(e,!0,-1),s=e.input.charCodeAt(e.position)),e.lineIndent>t&&0!==s)N(e,"bad indentation of a mapping entry");else if(e.lineIndentc&&(c=e.lineIndent),S(p))u++;else{if(e.lineIndent=t){a=!0,f=e.input.charCodeAt(e.position);continue}e.position=o,e.line=s,e.lineStart=c,e.lineIndent=u;break}}a&&(L(e,r,o,!1),B(e,e.line-s),r=o=e.position,a=!1),I(f)||(o=e.position+1),f=e.input.charCodeAt(++e.position)}if(L(e,r,o,!1),e.result)return 1;e.kind=l,e.result=p}}(e,i,g===n)&&(d=!0,null===e.tag&&(e.tag="?")):(d=!0,null===e.tag&&null===e.anchor||N(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===p&&(d=s&&K(e,r))),null!==e.tag&&"!"!==e.tag)if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&N(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),c=0,u=e.implicitTypes.length;c tag; it should be "'+l.kind+'", not "'+e.kind+'"'),l.resolve(e.result)?(e.result=l.construct(e.result),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):N(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")):N(e,"unknown tag !<"+e.tag+">");return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||d}function $(e,t){t=t||{},0!==(e=String(e)).length&&(10!==e.charCodeAt(e.length-1)&&13!==e.charCodeAt(e.length-1)&&(e+="\n"),65279===e.charCodeAt(0)&&(e=e.slice(1)));var n=new F(e,t),e=e.indexOf("\0");for(-1!==e&&(n.position=e,N(n,"null byte is not allowed in input")),n.input+="\0";32===n.input.charCodeAt(n.position);)n.lineIndent+=1,n.position+=1;for(;n.positiont/2-1){n=" ... ",i+=5;break}for(r="",o=this.position;ot/2-1){r=" ... ",o-=5;break}return a=this.buffer.slice(i,o),s.repeat(" ",e)+n+a+r+"\n"+s.repeat(" ",e+this.position-i+n.length)+"^"},i.prototype.toString=function(e){var t="";return this.name&&(t+='in "'+this.name+'" '),t+="at line "+(this.line+1)+", column "+(this.column+1),e||(e=this.getSnippet())&&(t+=":\n"+e),t},t.exports=i},{"./common":2}],7:[function(e,t,n){"use strict";var r=e("./common"),o=e("./exception"),a=e("./type");function s(e,t,i){var r=[];return e.include.forEach(function(e){i=s(e,t,i)}),e[t].forEach(function(n){i.forEach(function(e,t){e.tag===n.tag&&e.kind===n.kind&&r.push(t)}),i.push(n)}),i.filter(function(e,t){return-1===r.indexOf(t)})}function c(e){this.include=e.include||[],this.implicit=e.implicit||[],this.explicit=e.explicit||[],this.implicit.forEach(function(e){if(e.loadKind&&"scalar"!==e.loadKind)throw new o("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.")}),this.compiledImplicit=s(this,"implicit",[]),this.compiledExplicit=s(this,"explicit",[]),this.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{}};function i(e){n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e>16&255),o.push(r>>8&255),o.push(255&r)),r=r<<6|i.indexOf(t.charAt(a));return 0==(e=n%4*6)?(o.push(r>>16&255),o.push(r>>8&255),o.push(255&r)):18==e?(o.push(r>>10&255),o.push(r>>2&255)):12==e&&o.push(r>>4&255),s?s.from?s.from(o):new s(o):o},predicate:function(e){return s&&s.isBuffer(e)},represent:function(e){for(var t,n="",i=0,r=e.length,o=c,a=0;a>18&63],n+=o[i>>12&63],n+=o[i>>6&63],n+=o[63&i]),i=(i<<8)+e[a];return 0==(t=r%3)?(n+=o[i>>18&63],n+=o[i>>12&63],n+=o[i>>6&63],n+=o[63&i]):2==t?(n+=o[i>>10&63],n+=o[i>>4&63],n+=o[i<<2&63],n+=o[64]):1==t&&(n+=o[i>>2&63],n+=o[i<<4&63],n+=o[64],n+=o[64]),n}})},{"../type":13}],15:[function(e,t,n){"use strict";e=e("../type");t.exports=new e("tag:yaml.org,2002:bool",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)},construct:function(e){return"true"===e||"True"===e||"TRUE"===e},predicate:function(e){return"[object Boolean]"===Object.prototype.toString.call(e)},represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"})},{"../type":13}],16:[function(e,t,n){"use strict";var i=e("../common"),e=e("../type"),r=new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var o=/^[-+]?[0-9]+e/;t.exports=new e("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!r.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n=e.replace(/_/g,"").toLowerCase(),e="-"===n[0]?-1:1,i=[];return 0<="+-".indexOf(n[0])&&(n=n.slice(1)),".inf"===n?1==e?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===n?NaN:0<=n.indexOf(":")?(n.split(":").forEach(function(e){i.unshift(parseFloat(e,10))}),n=0,t=1,i.forEach(function(e){n+=e*t,t*=60}),e*n):e*parseFloat(n,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||i.isNegativeZero(e))},represent:function(e,t){if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(i.isNegativeZero(e))return"-0.0";return e=e.toString(10),o.test(e)?e.replace("e",".e"):e},defaultStyle:"lowercase"})},{"../common":2,"../type":13}],17:[function(e,t,n){"use strict";var i=e("../common"),e=e("../type");t.exports=new e("tag:yaml.org,2002:int",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i,r,o=e.length,a=0,s=!1;if(!o)return!1;if("-"!==(t=e[a])&&"+"!==t||(t=e[++a]),"0"===t){if(a+1===o)return!0;if("b"===(t=e[++a])){for(a++;a