Guest User

Untitled

a guest
Jul 13th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.00 KB | None | 0 0
  1. Old version:
  2. Each code includes every setting involved. i.e. One code tells the aircon to turn on to a set mode, temp, fan speed, & directional movement. So, I got the codes for each setting that I wanted and created a script for each, plus one to turn it off. Each script is labeled in a specific way. ie. Fan 4 (Fan 4th Speed), Cool 23l (Cool 23ºc Low Speed), Heat 14h (Heat 14ºc High Speed). I only did the settings & temps I'd be likely to use.
  3.  
  4. scripts:
  5. aircon_fan_1:
  6. sequence:
  7. - service: broadlink.send
  8. data:
  9. host: 192.168.1.4
  10. packet:
  11. - 'CODE'
  12. - delay: "00:00:01"
  13.  
  14. aircon_cool_23l:
  15. sequence:
  16. - service: broadlink.send
  17. data:
  18. host: 192.168.1.4
  19. packet:
  20. - 'CODE'
  21. - delay: "00:00:01"
  22.  
  23. aircon_heat_14h:
  24. sequence:
  25. - service: broadlink.send
  26. data:
  27. host: 192.168.1.4
  28. packet:
  29. - 'CODE'
  30. - delay: "00:00:01"
  31.  
  32. I then have 4 Input Selects: Aircon Fan, Aircon Cool, Aircon Heat, Aircon Last Setting. eg. The Heater:
  33.  
  34. input_select:
  35. aircon_heat:
  36. name: Heater
  37. options:
  38. - "Off"
  39. - "Heat 14l"
  40. - "Heat 14m"
  41. - "Heat 14h"
  42. - "Heat 15l"
  43. - "Heat 15m"
  44. - "Heat 15h"
  45. - "Heat 16l"
  46. - "Heat 16m"
  47. - "Heat 16h"
  48. - "Heat 17l"
  49. - "Heat 17m"
  50. - "Heat 17h"
  51. - "Heat 18l"
  52. - "Heat 18m"
  53. - "Heat 18h"
  54. - "Heat 19l"
  55. - "Heat 19m"
  56. - "Heat 19h"
  57. - "Heat 20l"
  58. - "Heat 20m"
  59. - "Heat 20h"
  60. icon: mdi:white-balance-sunny
  61.  
  62.  
  63. I then have the following automations. Trigger watches for changes in Fan/Heat/Cool Input Selects. Condition is a sensor checking that certain doors & windows are closed. Actions change the other input selects to Off, Changes Aircon Last Setting to the input selected, and runs the appropriate script to send the broadlink code:
  64.  
  65. automations:
  66. - alias: Aircon Off
  67. trigger:
  68. - platform: state
  69. entity_id: input_select.aircon_fan
  70. to: "Off"
  71. - platform: state
  72. entity_id: input_select.aircon_cool
  73. to: "Off"
  74. - platform: state
  75. entity_id: input_select.aircon_heat
  76. to: "Off"
  77. action:
  78. - service: script.aircon_off
  79.  
  80. - alias: Aircon Heat On
  81. trigger:
  82. - platform: template
  83. value_template: "{{not is_state('input_select.aircon_heat', 'Off')}}"
  84. condition:
  85. - condition: template
  86. value_template: "{{is_state('sensor.aircon_conditions','yes')}}"
  87. action:
  88. - service: input_select.select_option
  89. data:
  90. option: "Off"
  91. entity_id: input_select.aircon_fan
  92. - service: input_select.select_option
  93. data:
  94. option: "Off"
  95. entity_id: input_select.aircon_cool
  96. - service: input_select.select_option
  97. data_template:
  98. entity_id: input_select.aircon_last_setting
  99. option: "{{ states('input_select.aircon_heat') }}"
  100. - service_template: script.aircon_{{ states("input_select.aircon_last_setting")|replace(" ","_")|lower}}
  101.  
  102. - alias: Aircon Cool On
  103. trigger:
  104. - platform: template
  105. value_template: "{{not is_state('input_select.aircon_cool', 'Off')}}"
  106. condition:
  107. - condition: template
  108. value_template: "{{is_state('sensor.aircon_conditions','yes')}}"
  109. action:
  110. - service: input_select.select_option
  111. data:
  112. option: "Off"
  113. entity_id: input_select.aircon_fan
  114. - service: input_select.select_option
  115. data:
  116. option: "Off"
  117. entity_id: input_select.aircon_heat
  118. - service: input_select.select_option
  119. data_template:
  120. entity_id: input_select.aircon_last_setting
  121. option: "{{ states('input_select.aircon_cool') }}"
  122. - service_template: script.aircon_{{ states("input_select.aircon_last_setting")|replace(" ","_")|lower}}
  123.  
  124. - alias: Aircon Fan On
  125. trigger:
  126. - platform: template
  127. value_template: "{{not is_state('input_select.aircon_fan', 'Off')}}"
  128. condition:
  129. - condition: template
  130. value_template: "{{is_state('person.kat','home')}}"
  131. action:
  132. - service: input_select.select_option
  133. data:
  134. option: "Off"
  135. entity_id: input_select.aircon_heat
  136. - service: input_select.select_option
  137. data:
  138. option: "Off"
  139. entity_id: input_select.aircon_cool
  140. - service: input_select.select_option
  141. data_template:
  142. entity_id: input_select.aircon_last_setting
  143. option: "{{ states('input_select.aircon_fan') }}"
  144. - service_template: script.aircon_{{ states("input_select.aircon_last_setting")|replace(" ","_")|lower}}
  145.  
  146. The Aircon Last Setting allows me to also have a switch to turn on/off the aircon by applying the last selected setting:
  147.  
  148. switch:
  149. aircon:
  150. friendly_name: Air Conditioner Switch
  151. value_template: "{{ is_state('sensor.aircon', 'on') }}"
  152. turn_on:
  153. - service: input_select.select_option
  154. data_template:
  155. entity_id: >
  156. {% if 'Fan' in states.input_select.aircon_last_setting.state %}
  157. input_select.aircon_fan
  158. {% elif 'Cool' in states.input_select.aircon_last_setting.state %}
  159. input_select.aircon_cool
  160. {% elif 'Heat' in states.input_select.aircon_last_setting.state %}
  161. input_select.aircon_heat
  162. {% else %}
  163. script.nope
  164. {% endif %}
  165. option: "{{ states.input_select.aircon_last_setting.state }}"
  166. turn_off:
  167. - service_template: >
  168. {% if is_state('sensor.aircon', 'off')%}
  169. script.turn_on
  170. {% else %}
  171. input_select.select_option
  172. {% endif %}
  173. data_template:
  174. option: "Off"
  175. entity_id: >
  176. {% if is_state('sensor.aircon', 'off')%}
  177. script.nope
  178. {% elif not is_state('input_select.aircon_fan', "Off") %}
  179. input_select.aircon_fan
  180. {% elif not is_state('input_select.aircon_cool', "Off") %}
  181. input_select.aircon_cool
  182. {% elif not is_state('input_select.aircon_heat', "Off") %}
  183. input_select.aircon_heat
  184. {% else %}
  185. script.nope
  186. {% endif %}
  187. - service: automation.trigger
  188. entity_id: automation.aircon_off
  189. icon_template: >
  190. {% if is_state('sensor.aircon', 'off') %}
  191. mdi:air-conditioner
  192. {% elif 'Fan' in states.input_select.aircon_last_setting.state %}
  193. mdi:weather-windy
  194. {% elif 'Cool' in states.input_select.aircon_last_setting.state %}
  195. mdi:snowflake
  196. {% elif 'Heat' in states.input_select.aircon_last_setting.state %}
  197. mdi:white-balance-sunny
  198. {% else %}
  199. mdi:air-conditioner
  200. {% endif %}
  201.  
  202. End Result on my main view: Pressing the Last Aircon Setting toggles aircon on/off, or to change the setting, I can use the drop down menus. There might be a simpler way to achieve this, but as it is, it's working perfectly.
  203. ![24|397x500](upload://rdS554dXJJK8NIRe8nwEJJwh4d6.png)
  204.  
  205. I used Vertical-Stack-In-Card, Entities Card & Button Card in lovelace. This is the relevent code:
  206.  
  207. type: 'custom:vertical-stack-in-card'
  208. cards:
  209.  
  210. - type: 'custom:button-card'
  211. template: aircon_last
  212. entity: input_select.aircon_last_setting
  213.  
  214. - type: entities
  215. show_header_toggle: false
  216. entities:
  217. - entity: input_select.aircon_fan
  218. name: Fan
  219. - entity: input_select.aircon_cool
  220. name: Cool
  221. - entity: input_select.aircon_heat
  222. name: Heater
  223.  
  224. button_card_templates:
  225. aircon_last:
  226. layout: icon_name_state2nd
  227. show_name: true
  228. show_state: true
  229. icon: 'mdi:help'
  230. tap_action:
  231. action: call-service
  232. service: switch.toggle
  233. service_data:
  234. entity_id: switch.aircon
  235. hold_action:
  236. action: more-info
  237. state:
  238. - color: var(--primary-button-colour)
  239. icon: 'mdi:fan'
  240. operator: template
  241. value: >
  242. var ac = states['switch.aircon'].state; return (ac ===
  243. 'off' &&
  244. /F/.test(states['input_select.aircon_last_setting'].state))
  245. ;
  246. - color: var(--secondary-button-colour)
  247. icon: 'mdi:fan'
  248. operator: template
  249. value: >
  250. var ac = states['switch.aircon'].state; return (ac ===
  251. 'on' &&
  252. /F/.test(states['input_select.aircon_last_setting'].state))
  253. ;
  254. - color: var(--primary-button-colour)
  255. icon: 'mdi:snowflake'
  256. operator: template
  257. value: >
  258. var ac = states['switch.aircon'].state; return (ac ===
  259. 'off' &&
  260. /C/.test(states['input_select.aircon_last_setting'].state))
  261. ;
  262. - color: var(--secondary-button-colour)
  263. icon: 'mdi:snowflake'
  264. operator: template
  265. value: >
  266. var ac = states['switch.aircon'].state; return (ac ===
  267. 'on' &&
  268. /C/.test(states['input_select.aircon_last_setting'].state))
  269. ;
  270. - color: var(--primary-button-colour)
  271. icon: 'mdi:snowflake'
  272. operator: regex
  273. value:
  274. - C
  275. - color: var(--primary-button-colour)
  276. icon: 'mdi:white-balance-sunny'
  277. operator: template
  278. value: >
  279. var ac = states['switch.aircon'].state; return (ac ===
  280. 'off' &&
  281. /H/.test(states['input_select.aircon_last_setting'].state))
  282. ;
  283. - color: var(--secondary-button-colour)
  284. icon: 'mdi:white-balance-sunny'
  285. operator: template
  286. value: >
  287. var ac = states['switch.aircon'].state; return (ac ===
  288. 'on' &&
  289. /H/.test(states['input_select.aircon_last_setting'].state))
  290. ;
  291. styles:
  292. name:
  293. - font-size: 12px
  294. - padding: 0px 40px 0px 0px
  295. state:
  296. - padding: 0px 40px 0px 0px
Add Comment
Please, Sign In to add comment