Advertisement
zubir2k

TNB Home Assistant

Jun 18th, 2021 (edited)
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 6.43 KB | None | 0 0
  1. ############################################################################################
  2. ## Tenega Nasional Berhad (TNB) Malaysia Energy/Electric Bill Calculator for Home Assistant
  3. ## Suitable for eWelink RCCB Switch with Power Monitoring
  4. ############################################################################################
  5. ## Filename: configuration.yaml
  6. ############################################################################################
  7. ## Disclaimer: Readings is STRICTLY for reference only. It may not be the same with
  8. ## your actual electric bill.
  9. ############################################################################################
  10. ## This configuration has 6 parts;
  11. ## 1) sonoff integration
  12. ## 2) sensor
  13. ## 3) utility meter
  14. ## 4) monthly reset - https://pastebin.com/nwiPwLBD
  15. ## 5) [Optional] notification - telegram & file
  16. ## 6) [Optional] telegram integration
  17.  
  18. # Sonoff Integration - AlexxIT/SonoffLAN
  19. sonoff:
  20.   username: (enter your eWelink email here)
  21.   password: (enter your eWelink Password here)
  22.   force_update: [temperature, power]
  23.   scan_interval: '00:01:00'  
  24.   sensors: [temperature, humidity, power, current, voltage, rssi]
  25.   mode: local
  26.   reload: always  
  27.  
  28. # TNB energy reading
  29. sensor:
  30.   - platform: integration
  31.     name: Energy Consumed
  32.     source: sensor.sonoff_xxxxxxxxxx_power #sensor device dalam watt. Replace sonoff_xxxxxxxxxx with your own.
  33.   - platform: template
  34.     sensors:
  35.           daily_power_kw:
  36.             friendly_name: "Daily kWh"
  37.             unit_of_measurement: "kWh"
  38.             value_template: >-
  39.               {% set C = states('sensor.daily_energy_normal') | float %}
  40.               {{ (C / 1000) |round(2) }}
  41.             icon_template: mdi:counter
  42.           monthly_power_kw:
  43.             friendly_name: "Monthly kWh"
  44.             unit_of_measurement: "kWh"
  45.             value_template: >-
  46.               {% set C = states('sensor.monthly_energy_normal') | float %}
  47.               {{ (C / 1000) |round(2) }}
  48.             icon_template: mdi:counter
  49.            
  50. # Bacaan Blok TNB
  51.   - platform: template
  52.     sensors:
  53.       2ndbill_tnb_rm:
  54.         friendly_name: "2nd Jumlah Bill TNB"
  55.         unit_of_measurement: 'MYR'
  56.         icon_template: mdi:currency-usd
  57.         value_template: >-
  58.           {% if states('sensor.monthly_power_kw') | float < 201 %}
  59.             {% set Y = states('sensor.monthly_power_kw') | float %}
  60.             {{ (Y * 0.218) |round(2) }}
  61.           {% elif states('sensor.monthly_power_kw') | float >= 201 %}
  62.             43.60
  63.           {%- else %}
  64.             Unknown
  65.           {%- endif %}
  66.   - platform: template
  67.     sensors:
  68.       3rdbill_tnb_rm:
  69.         friendly_name: "3rd Jumlah Bill TNB"
  70.         unit_of_measurement: 'MYR'
  71.         icon_template: mdi:currency-usd
  72.         value_template: >-
  73.           {% if states('sensor.monthly_power_kw') | float <= 200 %}
  74.             0
  75.           {% elif states('sensor.monthly_power_kw') | float >= 301 %}
  76.             33.40
  77.           {% elif states('sensor.monthly_power_kw') | float >= 201 < 300 %}
  78.             {% set E = states('sensor.monthly_power_kw') | float - 200 %}
  79.             {{ (E * 0.334) |round(2) }}
  80.           {% elif states('sensor.monthly_power_kw') | float >= 301 %}
  81.             33.40
  82.           {%- else %}
  83.             Unknown
  84.           {%- endif %}
  85.   - platform: template
  86.     sensors:
  87.       4thbill_tnb_rm:
  88.         friendly_name: "4th Jumlah Bill TNB"
  89.         unit_of_measurement: 'MYR'
  90.         icon_template: mdi:currency-usd
  91.         value_template: >-
  92.           {% if states('sensor.monthly_power_kw') | float <= 300 %}
  93.             0
  94.           {% elif states('sensor.monthly_power_kw') | float >= 601 %}
  95.             154.80
  96.           {% elif states('sensor.monthly_power_kw') | float >= 301 < 600 %}
  97.             {% set F = states('sensor.monthly_power_kw') | float - 300 %}
  98.             {{ (F * 0.516) |round(2) }}
  99.           {% elif states('sensor.monthly_power_kw') | float >= 601 %}
  100.             154.80
  101.           {%- else %}
  102.             Unknown
  103.           {%- endif %}
  104.   - platform: template
  105.     sensors:
  106.       5thbill_tnb_rm:
  107.         friendly_name: "5th Jumlah Bill TNB"
  108.         unit_of_measurement: 'MYR'
  109.         icon_template: mdi:currency-usd
  110.         value_template: >-
  111.           {% if states('sensor.monthly_power_kw') | float <= 600 %}
  112.             0
  113.           {% elif states('sensor.monthly_power_kw') | float >= 901 %}
  114.             163.80
  115.           {% elif states('sensor.monthly_power_kw') | float >= 601 < 900 %}
  116.             {% set G = states('sensor.monthly_power_kw') | float - 600 %}
  117.             {{ (G * 0.546) |round(2) }}
  118.           {% elif states('sensor.monthly_power_kw') | float >= 901 %}
  119.             163.80
  120.           {%- else %}
  121.             Unknown
  122.           {%- endif %}
  123.          
  124. # Jumlah Bill TNB
  125.   - platform: template
  126.     sensors:
  127.       to_bill_tnb_rm:
  128.         friendly_name: "Total Bill TNB"
  129.         unit_of_measurement: 'MYR'
  130.         icon_template: mdi:currency-usd
  131.         value_template: >-
  132.           {% set H = states('sensor.2ndbill_tnb_rm') | float %}
  133.           {% set I = states('sensor.3rdbill_tnb_rm') | float %}
  134.           {% set J = states('sensor.4thbill_tnb_rm') | float %}
  135.           {% set K = states('sensor.5thbill_tnb_rm') | float %}
  136.           {{ (H + I + J + K) |round(2) }}
  137.          
  138. # Average Daily Bill TNB
  139.   - platform: template
  140.     sensors:
  141.       daily_tnb_rm:
  142.         friendly_name: "Daily Bill TNB"
  143.         unit_of_measurement: 'MYR'
  144.         icon_template: mdi:currency-usd
  145.         value_template: >-
  146.           {% set Y = states('sensor.daily_power_kw') | float %}
  147.           {{ (Y * 0.218) |round(2) }}
  148.  
  149. # TNB METER
  150. utility_meter:
  151.   daily_energy:
  152.     source: sensor.energy_consumed
  153.     cycle: daily
  154.     tariffs:
  155.     - normal
  156.   monthly_energy:
  157.     source: sensor.energy_consumed
  158.     cycle: yearly
  159.     tariffs:
  160.     - normal
  161.  
  162. # Notification
  163. notify:
  164.   - platform: telegram
  165.     name: notify.telegrammaster
  166.     chat_id: !secret telegram_master
  167.   - platform: file
  168.     filename: /config/www/reports/monthly_tnb.csv # path where the file will be generated.
  169.     name: Monthly TNB CSV
  170.     timestamp: true
  171.    
  172. telegram_bot:
  173.   - platform: polling
  174.     api_key: !secret telegram_key
  175.     allowed_chat_ids:
  176.      - !secret telegram_master
  177.   - platform: webhooks
  178.     api_key: !secret telegram_key
  179.     url: https://yourHAname.duckdns.org # or your own domain name
  180.     allowed_chat_ids:
  181.      - !secret telegram_master
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement