diff --git a/Home_Assistant/blueprints/hasp_Display_Weather_Condition_Icon_Only.yaml b/Home_Assistant/blueprints/hasp_Display_Weather_Condition_Icon_Only.yaml new file mode 100644 index 0000000..9aa6f29 --- /dev/null +++ b/Home_Assistant/blueprints/hasp_Display_Weather_Condition_Icon_Only.yaml @@ -0,0 +1,295 @@ +blueprint: + name: "HASP p[x].b[y] displays the current weather condition icon only" + description: | + + # Description + + A HASP button displays the current weather condition icon only + + ![Preview](https://raw.githubusercontent.com/HASwitchPlate/HASPone/main/images/hasp_Display_Weather_Condition_Icon_Only.png) + + ## HASP Page and Button reference + +
+ + This automation is designed to work with the full-width buttons found on pages 1-3 + + | Pages 1-3 | + |-----------| + | ![Pages 1-3](https://raw.githubusercontent.com/HASwitchPlate/HASPone/main/images/NextionUI_p1-p3_4buttons.png) | + +
+ domain: automation + input: + haspdevice: + name: "HASP Device" + description: "Select the HASP device" + selector: + device: + integration: mqtt + manufacturer: "HASwitchPlate" + model: "HASPone v1.0.0" + hasppage: + name: "HASP Page" + description: "Select the HASP page (1-3) for the temperature" + default: 1 + selector: + number: + min: 1 + max: 11 + mode: slider + unit_of_measurement: page + haspbutton: + name: "HASP Button" + description: "Select the HASP button (4-7) for the temperature. Refer to the object map in the HASP documentation." + default: 4 + selector: + number: + min: 4 + max: 15 + mode: slider + unit_of_measurement: button + weather_provider: + name: "Weather provider" + description: "Select the weather provider to obtain the temperature" + selector: + entity: + domain: weather + +mode: parallel +max_exceeded: silent + +variables: + haspname: >- + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^sensor\.") -%} + {{- entity|regex_replace(find="^sensor\.", replace="", ignorecase=true)|regex_replace(find="_sensor(?:_\d+|)$", replace="", ignorecase=true) -}} + {{ break }} + {%- endif -%} + {%- endfor -%} + haspsensor: >- + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^sensor\..+_sensor(?:_\d+|)$") -%} + {{ entity }} + {{ break }} + {%- endif -%} + {%- endfor -%} + hasppage: !input hasppage + haspbutton: !input haspbutton + weather_provider: !input weather_provider + haspobject: '{{ "p[" ~ hasppage ~ "].b[" ~ haspbutton ~ "]" }}' + commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}' + jsoncommandtopic: '{{ "hasp/" ~ haspname ~ "/command/json" }}' + jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}' + icon: >- + {%- set condition=states(weather_provider) -%} + {%- if condition == "clear-night" -%} +  + {%- elif condition == "cloudy" -%} +  + {%- elif condition == "fog" -%} +  + {%- elif condition == "hail" -%} +  + {%- elif condition == "lightning" -%} +  + {%- elif condition == "lightning-rainy" -%} +  + {%- elif condition == "partlycloudy" -%} +  + {%- elif condition == "pouring" -%} +  + {%- elif condition == "rainy" -%} +  + {%- elif condition == "snowy" -%} +  + {%- elif condition == "snowy-rainy" -%} +  + {%- elif condition == "sunny" -%} +  + {%- elif condition == "windy" -%} +  + {%- elif condition == "windy-variant" -%} +  + {%- elif condition == "exceptional" -%} +  + {%- else -%} +  + {%- endif -%} + text: >- + {{- + states(weather_provider) | + replace("windy-variant","windy") | + replace("clear-night","clear night") | + replace("partlycloudy","partly cloudy") | + replace("lightning-rainy","lightning & rain") | + replace("snowy-rainy","snow & rain") | + title + -}} + font: >- + {%- set weatherlength = text | length -%} + {%- if weatherlength < 7 -%} + 8 + {%- elif weatherlength < 12 -%} + 7 + {%- else -%} + 6 + {%- endif -%} + ypos: "{{(haspbutton|int - 4) * 67 + 2}}" + xpos: 0 + iconwidth: 65 + iconheight: 65 + iconfont: 8 + xcen: 1 + ycen: 1 + activepage: >- + {%- set activepage = namespace() -%} + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^number\..*_active_page(?:_\d+|)$") -%} + {%- set activepage.entity=entity -%} + {{ break }} + {%- endif -%} + {%- endfor -%} + {% if states(activepage.entity)|lower == "none" %}-1{% else %}{{ states(activepage.entity) | int }}{% endif %} + selectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedforegroundcolor/rgb" }}' + selectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedbackgroundcolor/rgb" }}' + unselectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}' + unselectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}' + selectedfg: >- + {%- set color = namespace() -%} + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%} + {%- set color.source=entity -%} + {{ break }} + {%- endif -%} + {%- endfor -%} + {%- set brightness = state_attr(color.source, "brightness")|int / 255 -%} + {%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%} + {%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%} + {%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%} + {{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }} + selectedbg: >- + {%- set color = namespace() -%} + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%} + {%- set color.source=entity -%} + {{ break }} + {%- endif -%} + {%- endfor -%} + {%- set brightness = state_attr(color.source, "brightness")|int / 255 -%} + {%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%} + {%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%} + {%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%} + {{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }} + unselectedfg: >- + {%- set color = namespace() -%} + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%} + {%- set color.source=entity -%} + {{ break }} + {%- endif -%} + {%- endfor -%} + {%- set brightness = state_attr(color.source, "brightness")|int / 255 -%} + {%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%} + {%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%} + {%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%} + {{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }} + unselectedbg: >- + {%- set color = namespace() -%} + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%} + {%- set color.source=entity -%} + {{ break }} + {%- endif -%} + {%- endfor -%} + {%- set brightness = state_attr(color.source, "brightness")|int / 255 -%} + {%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%} + {%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%} + {%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%} + {{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }} + +trigger_variables: + haspdevice: !input haspdevice + haspname: >- + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^sensor\.") -%} + {{- entity|regex_replace(find="^sensor\.", replace="", ignorecase=true)|regex_replace(find="_sensor(?:_\d+|)$", replace="", ignorecase=true) -}} + {{ break }} + {%- endif -%} + {%- endfor -%} + haspsensor: >- + {%- for entity in device_entities(haspdevice) -%} + {%- if entity|regex_search("^sensor\..+_sensor(?:_\d+|)$") -%} + {{ entity }} + {{ break }} + {%- endif -%} + {%- endfor -%} + jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}' + selectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedforegroundcolor/rgb" }}' + selectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedbackgroundcolor/rgb" }}' + unselectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}' + unselectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}' + +trigger: + - platform: state + entity_id: !input weather_provider + - platform: homeassistant + event: start + - platform: template + value_template: "{{ is_state(haspsensor, 'ON') }}" + - platform: mqtt + topic: "{{jsontopic}}" + - platform: mqtt + topic: "{{selectedfgtopic}}" + - platform: mqtt + topic: "{{selectedbgtopic}}" + - platform: mqtt + topic: "{{unselectedfgtopic}}" + - platform: mqtt + topic: "{{unselectedbgtopic}}" + +condition: + - condition: template + value_template: "{{ is_state(haspsensor, 'ON') }}" + +action: + - choose: + ######################################################################### + # RUN ACTIONS or Home Assistant Startup or HASP Connect + # Apply styles, place text, and then place icon if our target page is currently active + - conditions: + - condition: template + value_template: >- + {{- + (trigger is not defined) + or + ((trigger.platform == 'homeassistant') and (trigger.event == 'start')) + or + ((trigger.platform == 'template') and (trigger.entity_id == haspsensor) and (trigger.to_state.state == 'ON')) + -}} + sequence: + - service: mqtt.publish + data: + topic: "{{jsoncommandtopic}}" + payload: >- + ["{{haspobject}}.font={{font}}", + "{{haspobject}}.xcen={{xcen}}", + "{{haspobject}}.ycen={{ycen}}", + "{{haspobject}}.pco={{selectedfg}}", + "{{haspobject}}.bco={{selectedbg}}", + "{{haspobject}}.pco2={{unselectedfg}}", + "{{haspobject}}.bco2={{unselectedbg}}", + "{{haspobject}}.txt=\"{{icon}}\""] + ######################################################################### + # Update weather condition if our weather provider changed state + - conditions: + - condition: template + value_template: '{{ (trigger.platform == "state") and (trigger.entity_id == weather_provider) }}' + sequence: + - service: mqtt.publish + data: + topic: "{{jsoncommandtopic}}" + payload: >- + ["{{haspobject}}.pco={{selectedfg}}", + "{{haspobject}}.font={{font}}", + "{{haspobject}}.txt=\"{{icon}} \""]