Advertisement
gio_aggiustatutto

Code to be added below the one provided by ESPHome

Oct 14th, 2024 (edited)
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.83 KB | None | 0 0
  1. #PASTE THIS CODE BELOW THE ONE GIVEN BY ESPHome
  2.  
  3. #JSY energy meter protocol
  4. uart:
  5.   id: mod_bus
  6.   tx_pin: 17
  7.   rx_pin: 16
  8.   baud_rate: 4800
  9.   stop_bits: 1
  10.  
  11. modbus:
  12.   id: modbus1
  13.  
  14. modbus_controller:
  15.   - id: jsymk
  16.     #modbus device address
  17.     address: 0x1
  18.     modbus_id: modbus1
  19.     update_interval: 12s
  20.     command_throttle: 50ms
  21.  
  22. i2c:
  23.   sda: 21
  24.   scl: 22
  25.  
  26. font:
  27.   - file:
  28.       type: gfonts
  29.       family: Baloo+Bhaijaan+2
  30.       weight: 500
  31.     id: baloo_18_500
  32.     size: 18
  33.  
  34.   - file:
  35.       type: gfonts
  36.       family: Baloo+Bhaijaan+2
  37.       weight: 700
  38.     id: baloo_32_700
  39.     size: 32
  40.  
  41.   - file:
  42.       type: gfonts
  43.       family: Baloo+Bhaijaan+2
  44.       weight: 700
  45.     id: baloo_18_700
  46.     size: 18
  47.  
  48.   - file: "gfonts://Material+Symbols+Outlined"
  49.     id: icons_18
  50.     size: 18
  51.     glyphs: ["\ue63e", "\ue648"] # mdi-wifi, mdi-wifi-off
  52.  
  53. display:
  54.   - platform: ssd1306_i2c
  55.     model: "SSD1306 128x64"
  56.     address: 0x3C
  57.     id: oled
  58.     rotation: 180°
  59.     lambda: |-
  60.       it.print(-1, -4, id(baloo_18_500), "Energy Meter");
  61.  
  62.       if(id(connection_status).state == 1) {
  63.         it.print(it.get_width(), 0, id(icons_18), TextAlign::TOP_RIGHT, "\ue63e");        
  64.       }
  65.       else {
  66.         it.print(it.get_width(), 0, id(icons_18), TextAlign::TOP_RIGHT, "\ue648");
  67.       }
  68.  
  69.       it.printf(it.get_width()/2, 38, id(baloo_32_700), TextAlign::CENTER, "%.1f W", id(power1).state);
  70.  
  71.       it.printf(0, it.get_height() + 12, id(baloo_18_700), TextAlign::BOTTOM_LEFT, "%.1f V", id(voltage1).state);
  72.  
  73.       it.printf(it.get_width(), it.get_height() + 12, id(baloo_18_700), TextAlign::BOTTOM_RIGHT, "%.1f A", id(current1).state);
  74.  
  75.  
  76. binary_sensor:
  77. # Connection status
  78.   - platform: status
  79.     name: "Status"
  80.     id: connection_status
  81.  
  82. sensor:
  83. # First channel voltage
  84.   - platform: modbus_controller
  85.     modbus_controller_id: jsymk
  86.     id: voltage1
  87.     name: "Voltage"
  88.     icon: mdi:alpha-v-box
  89.     device_class: energy
  90.     address: 0x0048
  91.     unit_of_measurement: "V"
  92.     register_type: holding
  93.     value_type: U_DWORD
  94.     accuracy_decimals: 1
  95.     filters:
  96.       - multiply: 0.0001
  97.     register_count: 1
  98.     response_size: 4
  99.  
  100. # First channel current
  101.   - platform: modbus_controller
  102.     modbus_controller_id: jsymk
  103.     id: current1
  104.     name: "Current 1"
  105.     icon: mdi:current-ac
  106.     device_class: energy
  107.     address: 0x0049
  108.     unit_of_measurement: "A"
  109.     register_type: holding
  110.     value_type: U_DWORD
  111.     accuracy_decimals: 1
  112.     filters:
  113.       - multiply: 0.0001
  114.     register_count: 1
  115.     response_size: 4
  116.  
  117. # First channel power
  118.   - platform: modbus_controller
  119.     modbus_controller_id: jsymk
  120.     id: power1
  121.     name: "Power 1"
  122.     icon: mdi:lightning-bolt
  123.     device_class: energy
  124.     address: 0x004A
  125.     unit_of_measurement: "W"
  126.     register_type: holding
  127.     value_type: U_DWORD
  128.     accuracy_decimals: 1
  129.     filters:
  130.       - multiply: 0.0001
  131.     register_count: 1
  132.     response_size: 4
  133.  
  134. # First channel energy
  135.   - platform: modbus_controller
  136.     modbus_controller_id: jsymk
  137.     id: energy1
  138.     name: "Energy 1"
  139.     icon: mdi:lightning-bolt
  140.     device_class: energy
  141.     address: 0x004B
  142.     unit_of_measurement: "kWh"
  143.     state_class: total
  144.     register_type: holding
  145.     value_type: U_DWORD
  146.     accuracy_decimals: 1
  147.     filters:
  148.       - multiply: 0.0001
  149.     register_count: 1
  150.     response_size: 4
  151.  
  152. # First channel power factor
  153.   - platform: modbus_controller
  154.     modbus_controller_id: jsymk
  155.     id: powerfactor1
  156.     name: "Power Factor 1"
  157.     icon: mdi:alpha-p-box
  158.     device_class: energy
  159.     address: 0x004C
  160.     register_type: holding
  161.     value_type: U_DWORD
  162.     accuracy_decimals: 1
  163.     filters:
  164.       - multiply: 0.001
  165.     register_count: 1
  166.     response_size: 4
  167.  
  168. # First channel negative active energy
  169.   - platform: modbus_controller
  170.     modbus_controller_id: jsymk
  171.     id: negativeactiveenergy1
  172.     #name: "Negative Active Energy 1"
  173.     icon: mdi:lightning-bolt
  174.     device_class: energy
  175.     address: 0x004D
  176.     unit_of_measurement: "kWh"
  177.     state_class: total
  178.     register_type: holding
  179.     value_type: U_DWORD
  180.     accuracy_decimals: 1
  181.     filters:
  182.       - multiply: 0.0001
  183.     register_count: 1
  184.     response_size: 4
  185.  
  186. # First channel current direction
  187.   - platform: modbus_controller
  188.     modbus_controller_id: jsymk
  189.     id: direction1
  190.     #name: "Current Direction 1"
  191.     icon: mdi:arrow-right
  192.     device_class: energy
  193.     address: 0x004E
  194.     register_type: holding
  195.     value_type: U_DWORD
  196.     accuracy_decimals: 0
  197.     bitmask: 0X01000000
  198.     filters:
  199.       - multiply: 1
  200.     register_count: 1
  201.     response_size: 4
  202.  
  203. # Frequency
  204.   - platform: modbus_controller
  205.     modbus_controller_id: jsymk
  206.     id: frequency
  207.     name: "Frequency"
  208.     icon: mdi:sine-wave
  209.     device_class: energy
  210.     address: 0x004F
  211.     unit_of_measurement: "Hz"
  212.     register_type: holding
  213.     value_type: U_DWORD
  214.     accuracy_decimals: 1
  215.     filters:
  216.       - multiply: 0.01
  217.     register_count: 1
  218.     response_size: 4
  219.  
  220. # Second channel voltage
  221.   - platform: modbus_controller
  222.     modbus_controller_id: jsymk
  223.     id: voltage2
  224.     #name: "Voltage 2"
  225.     icon: mdi:alpha-v-box
  226.     device_class: energy
  227.     address: 0x0050
  228.     unit_of_measurement: "V"
  229.     register_type: holding
  230.     value_type: U_DWORD
  231.     accuracy_decimals: 1
  232.     filters:
  233.       - multiply: 0.0001
  234.     register_count: 1
  235.     response_size: 4
  236.  
  237. # Second channel current
  238.   - platform: modbus_controller
  239.     modbus_controller_id: jsymk
  240.     id: current2
  241.     name: "Current 2"
  242.     icon: mdi:current-ac
  243.     device_class: energy
  244.     address: 0x0051
  245.     unit_of_measurement: "A"
  246.     register_type: holding
  247.     value_type: U_DWORD
  248.     accuracy_decimals: 1
  249.     filters:
  250.       - multiply: 0.0001
  251.     register_count: 1
  252.     response_size: 4
  253.  
  254. # Second channel power
  255.   - platform: modbus_controller
  256.     modbus_controller_id: jsymk
  257.     id: power2
  258.     name: "Power 2"
  259.     icon: mdi:lightning-bolt
  260.     device_class: energy
  261.     address: 0x0052
  262.     unit_of_measurement: "W"
  263.     register_type: holding
  264.     value_type: U_DWORD
  265.     accuracy_decimals: 1
  266.     filters:
  267.       - multiply: 0.0001
  268.     register_count: 1
  269.     response_size: 4
  270.  
  271. # Second channel energy
  272.   - platform: modbus_controller
  273.     modbus_controller_id: jsymk
  274.     id: energy2
  275.     name: "Energy 2"
  276.     icon: mdi:lightning-bolt
  277.     device_class: energy
  278.     address: 0x0053
  279.     unit_of_measurement: "kWh"
  280.     state_class: total
  281.     register_type: holding
  282.     value_type: U_DWORD
  283.     accuracy_decimals: 1
  284.     filters:
  285.       - multiply: 0.0001
  286.     register_count: 1
  287.     response_size: 4
  288.  
  289. # Second channel power factor
  290.   - platform: modbus_controller
  291.     modbus_controller_id: jsymk
  292.     id: powerfactor2
  293.     name: "Power Factor 2"
  294.     icon: mdi:alpha-p-box
  295.     device_class: energy
  296.     address: 0x0054
  297.     register_type: holding
  298.     value_type: U_DWORD
  299.     accuracy_decimals: 1
  300.     filters:
  301.       - multiply: 0.001
  302.     register_count: 1
  303.     response_size: 4
  304.  
  305. # Second channel negative active energy
  306.   - platform: modbus_controller
  307.     modbus_controller_id: jsymk
  308.     id: negativeactiveenergy2
  309.     #name: "Negative Active Energy 2"
  310.     icon: mdi:lightning-bolt
  311.     device_class: energy
  312.     address: 0x0055
  313.     unit_of_measurement: "kWh"
  314.     state_class: total
  315.     register_type: holding
  316.     value_type: U_DWORD
  317.     accuracy_decimals: 1
  318.     filters:
  319.       - multiply: 0.0001
  320.     register_count: 1
  321.     response_size: 4
  322.  
  323. # Second channel current direction
  324.   - platform: modbus_controller
  325.     modbus_controller_id: jsymk
  326.     id: direction2
  327.     #name: "Current Direction 2"
  328.     icon: mdi:arrow-right
  329.     device_class: energy
  330.     address: 0x004E
  331.     register_type: holding
  332.     value_type: U_DWORD
  333.     accuracy_decimals: 0
  334.     bitmask: 0X00010000
  335.     filters:
  336.       - multiply: 1
  337.     register_count: 1
  338.     response_size: 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement