Guest User

Home-Assistant Hacky BOND Fans

a guest
May 10th, 2019
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 10.72 KB | None | 0 0
  1. ## Hacky Bond Integration ##
  2. #
  3. # Place the below directly in your configuration.yaml file.
  4. #
  5. # First make sure you have your BOND-Token, device ID's, and device command ID's by following the directions here:
  6. # http://docs-local.appbond.com/#section/Getting-Started
  7. #
  8. # All components will be set up with a base 'fan name'. This fan name will be used when calling the generic scripts
  9. # and this fan name will be used to check and update input_booleans, input_selects, and call shell_commands. I.E.:
  10. # 'master_fan' is my fan name, 'master_fan_pwr' is a shell command, 'master_fan_state' is an input boolean.
  11.  
  12. ## Shell Commands to execute commands against a local BOND device
  13. #
  14. # Be sure to set the Bond Token, IP, device ID, and command ID's correctly.
  15. #
  16. # Create a shell command group for each named fan you have.
  17. shell_command:
  18.   master_fan_light_toggle: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/DEVICEID/commands/COMMANDID/tx -X PUT -d {}'
  19.   master_fan_spd_low: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/DEVICEID/commands/COMMANDID/tx -X PUT -d {}'
  20.   master_fan_spd_medium: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/DEVICEID/commands/COMMANDID/tx -X PUT -d {}'
  21.   master_fan_spd_high: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/DEVICEID/commands/COMMANDID/tx -X PUT -d {}'
  22.   master_fan_pwr: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/DEVICEID/commands/COMMANDID/tx -X PUT -d {}'
  23.  
  24.   livingroom_fan_light_toggle: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/00000003/commands/COMMANDID/tx -X PUT -d {}'
  25.   livingroom_fan_spd_low: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/00000003/commands/COMMANDID/tx -X PUT -d {}'
  26.   livingroom_fan_spd_medium: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/00000003/commands/COMMANDID/tx -X PUT -d {}'
  27.   livingroom_fan_spd_high: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/00000003/commands/COMMANDID/tx -X PUT -d {}'
  28.   livingroom_fan_pwr: 'curl -H "BOND-Token: xxxxxxxxxxxxxxxx" -i http://192.168.86.107/v2/devices/00000003/commands/COMMANDID/tx -X PUT -d {}'
  29.  
  30. ## Fan and Fan Light States
  31. #
  32. # Be sure to have a state and light_state for each named fan.
  33. # Note that there is no initial value here - we want to retain the last value.
  34. #
  35. # If the fan state ever becomes out of sync with what home-assistant knows then
  36. # you can either modify this value to match the state, or use the fan controller
  37. # and change the fan to match what home-assistant knows.
  38. input_boolean:
  39.   master_fan_state:
  40.     name: Master Fan State
  41.  
  42.   master_fan_light_state:
  43.     name: Master Fan Light State
  44.    
  45.   livingroom_fan_state:
  46.     name: Livingroom Fan State
  47.  
  48.   livingroom_fan_light_state:
  49.     name: Livingroom Fan Light State
  50.  
  51. ## Fan Speed States
  52. #
  53. # Note that there is no initial value here - we want to retain the last value.
  54. # The first option will be the 'default' option when first started.
  55. input_select:
  56.   master_fan_speed:
  57.     name: Master Fan Speed
  58.     options:
  59.      - medium
  60.       - low
  61.       - high
  62.      
  63.   livingroom_fan_speed:
  64.     name: Livingroom Fan Speed
  65.     options:
  66.      - medium
  67.       - low
  68.       - high
  69.  
  70. ## Bond Scripts
  71. #
  72. # These scripts control turning the light and fan on and off, as well as setting the state.
  73. # They utilize the input_booleans and input_selects to ensure that we don't turn the fan
  74. # or the light on or off when we don't need to. This is important primarily when we're dealing
  75. # with devices that have toggle-only power buttons for either the light or fan operation.
  76. #
  77. # Use these scripts whenever you control a bond device to ensure that the states are stored correctly
  78. # in home-assistant.
  79. script:
  80.  
  81.   # Turn a Bond fan on only if it is currently off.
  82.   # Sets the speed back to the last selected speed.
  83.   #
  84.   # Variables:
  85.   # fan: The name of the fan you want to turn on.
  86.   bond_fan_on:
  87.     sequence:
  88.      # Only proceed if the fan is currently off
  89.       - condition: template
  90.         value_template: "{{ is_state('input_boolean.' + fan + '_state', 'off') }}"
  91.        
  92.       # Return the fan to its previous speed
  93.       - service: script.bond_fan_set_speed
  94.         data_template:
  95.           fan: "{{ fan }}"
  96.           speed: "{{ states('input_select.' + fan + '_speed') }}"
  97.  
  98.   # Turn a Bond fan off only if it is currently on.
  99.   #
  100.   # Variables:
  101.   # fan: The name of the fan you want to turn off.
  102.   bond_fan_off:
  103.     sequence:
  104.      # Only proceed if the fan is currently on
  105.       - condition: template
  106.         value_template: "{{ is_state('input_boolean.' + fan + '_state', 'on') }}"
  107.        
  108.       # Set the fan off
  109.       - service: input_boolean.turn_off
  110.         data_template:
  111.           entity_id: "{{ 'input_boolean.' + fan + '_state' }}"
  112.              
  113.       # Power off the fan
  114.       - service_template: "{{ 'shell_command.' + fan + '_pwr' }}"
  115.  
  116.   # Set the speed of a Bond fan only if it is off or if the speed
  117.   # is different than the currently selected speed.
  118.   #
  119.   # Variables:
  120.   # fan: The name of the fan you want to turn on.
  121.   # speed: The speed to set. Must be a value from the input_select.
  122.   bond_fan_set_speed:
  123.     sequence:
  124.      # Only proceed if the fan is off OR the state is not the current speed
  125.       - condition: template
  126.         value_template: "{{ is_state('input_boolean.' + fan + '_state', 'off') or not is_state('input_select.' + fan + '_speed', speed) }}"
  127.        
  128.       # Only proceed if the given speed exists (sanity check)
  129.       - condition: template
  130.         value_template: "{{ speed in(states.input_select[fan+'_speed'].attributes.options) }}"
  131.      
  132.       # Set the fan on
  133.       - service: input_boolean.turn_on
  134.         data_template:
  135.           entity_id: "{{ 'input_boolean.' + fan + '_state' }}"
  136.              
  137.       # Set the speed of the fan
  138.       - service: input_select.select_option
  139.         data_template:
  140.           entity_id: "{{ 'input_select.' + fan + '_speed' }}"
  141.           option: "{{ speed }}"
  142.              
  143.       # Call to set the speed of the fan
  144.       - service_template: >
  145.          {% if speed == 'low' %}
  146.             {{ 'shell_command.' + fan + '_spd_low' }}
  147.           {% elif speed == 'medium' %}
  148.             {{ 'shell_command.' + fan + '_spd_medium' }}
  149.           {% elif speed == 'high' %}
  150.             {{ 'shell_command.' + fan + '_spd_high' }}
  151.           {% endif %}
  152.  
  153.   # Turn a Bond fan light on only if it is currently off.
  154.   #
  155.   # Variables:
  156.   # fan: The name of the fan with the light you want to turn off.
  157.   bond_fan_light_on:
  158.     sequence:
  159.      # Only proceed if the fan light is currently off
  160.       - condition: template
  161.         value_template: "{{ is_state('input_boolean.' + fan + '_light_state', 'off') }}"
  162.        
  163.       # Set the fan light on
  164.       - service: input_boolean.turn_on
  165.         data_template:
  166.           entity_id: "{{ 'input_boolean.' + fan + '_light_state' }}"
  167.              
  168.       # Toggle the fan light on
  169.       - service_template: "{{ 'shell_command.' + fan + '_light_toggle' }}"
  170.  
  171.   # Turn a Bond fan light off only if it is currently on.
  172.   #
  173.   # Variables:
  174.   # fan: The name of the fan with the light you want to turn off.
  175.   bond_fan_light_off:
  176.     sequence:
  177.      # Only proceed if the fan light is currently on
  178.       - condition: template
  179.         value_template: "{{ is_state('input_boolean.' + fan + '_light_state', 'on') }}"
  180.        
  181.       # Set the fan light off
  182.       - service: input_boolean.turn_off
  183.         data_template:
  184.           entity_id: "{{ 'input_boolean.' + fan + '_light_state' }}"
  185.              
  186.       # Toggle the fan light off
  187.       - service_template: "{{ 'shell_command.' + fan + '_light_toggle' }}"
  188.  
  189. ## Bond Fan Light Toggle Switches
  190. #
  191. # The ceiling fans I am using only support off/on or hold-to-dim.
  192. # To just give me the minimum functionality of an on-off light, I use a
  193. # template switch.
  194. switch:
  195.   - platform: template
  196.     switches:
  197.       master_fan_light:
  198.         value_template: "{{ is_state('input_boolean.master_fan_light_state', 'on') }}"
  199.         turn_on:
  200.           - service: script.bond_fan_light_on
  201.             data:
  202.               fan: 'master_fan'
  203.              
  204.         turn_off:
  205.           - service: script.bond_fan_light_off
  206.             data:
  207.               fan: 'master_fan'
  208.  
  209.       livingroom_fan_light:
  210.         value_template: "{{ is_state('input_boolean.livingroom_fan_light_state', 'on') }}"
  211.         turn_on:
  212.           - service: script.bond_fan_light_on
  213.             data:
  214.               fan: 'livingroom_fan'
  215.              
  216.         turn_off:
  217.           - service: script.bond_fan_light_off
  218.             data:
  219.               fan: 'livingroom_fan'
  220.  
  221. ## Bond Fan Lights
  222. #
  223. # Convert the light toggle switches into light components that only
  224. # support on|off functionality.
  225. light:
  226.   - platform: switch
  227.     name: Master Fan Light
  228.     entity_id: switch.master_fan_light
  229.    
  230.   - platform: switch
  231.     name: Livingroom Fan Light
  232.     entity_id: switch.livingroom_fan_light
  233.  
  234. ## Bond Fans
  235. #
  236. # Create a fan component using the input_boolean and input_select objects to
  237. # track state, and then utilize the scripts to turn the fan off, on, and set
  238. # the speed.
  239. fan:
  240.   - platform: template
  241.     fans:
  242.       master_fan:
  243.         friendly_name: "Master Fan"
  244.         value_template: "{{ states('input_boolean.master_fan_state') }}"
  245.         speed_template: "{{ states('input_select.master_fan_speed') }}"
  246.         speeds:
  247.          - 'high'
  248.           - 'medium'
  249.           - 'low'
  250.          
  251.         turn_on:
  252.           - service: script.bond_fan_on
  253.             data:
  254.               fan: 'master_fan'
  255.              
  256.         turn_off:
  257.           - service: script.bond_fan_off
  258.             data:
  259.               fan: 'master_fan'
  260.          
  261.         set_speed:
  262.           - service: script.bond_fan_set_speed
  263.             data_template:
  264.               fan: 'master_fan'
  265.               speed: "{{ speed }}"
  266.              
  267.       livingroom_fan:
  268.         friendly_name: "Livingroom Fan"
  269.         value_template: "{{ states('input_boolean.livingroom_fan_state') }}"
  270.         speed_template: "{{ states('input_select.livingroom_fan_speed') }}"
  271.         speeds:
  272.          - 'high'
  273.           - 'medium'
  274.           - 'low'
  275.          
  276.         turn_on:
  277.           - service: script.bond_fan_on
  278.             data:
  279.               fan: 'livingroom_fan'
  280.              
  281.         turn_off:
  282.           - service: script.bond_fan_off
  283.             data:
  284.               fan: 'livingroom_fan'
  285.          
  286.         set_speed:
  287.           - service: script.bond_fan_set_speed
  288.             data_template:
  289.               fan: 'livingroom_fan'
  290.               speed: "{{ speed }}"
Add Comment
Please, Sign In to add comment