Advertisement
ulfben

modbus_sungrow_2.yaml

Sep 11th, 2024
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 107.20 KB | None | 0 0
  1. # Home Assistant Sungrow inverter integration
  2. # https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant
  3. # by Martin Kaiser
  4. # last update: 2024-07-17
  5. #
  6. # Note: This YAML file will only work with Home Assistant >= 2023.10
  7. # This file has been edited to add a second inverter to HA.
  8. # See details here: https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/issues/43#issuecomment-2282202356
  9.  
  10. modbus:
  11.   - name: SungrowSHx 2
  12.     type: tcp
  13.     host: !secret sungrow_modbus_host_ip_inv2
  14.     port: !secret sungrow_modbus_port_inv2
  15.     sensors:
  16.       - name: Sungrow device type code 2
  17.         unique_id: sg_dev_code_2
  18.         device_address: !secret sungrow_modbus_slave_inv2
  19.         address: 4999 # reg 5000
  20.         input_type: input
  21.         data_type: uint16
  22.         scan_interval: 600
  23.  
  24.       - name: Daily PV generation & battery discharge 2
  25.         unique_id: sg_daily_pv_gen_battery_discharge_2
  26.         device_address: !secret sungrow_modbus_slave_inv2
  27.         address: 5002 # reg 5003
  28.         input_type: input
  29.         data_type: uint16
  30.         precision: 1
  31.         unit_of_measurement: kWh
  32.         device_class: energy
  33.         state_class: total_increasing
  34.         scale: 0.1
  35.         scan_interval: 600
  36.  
  37.       - name: Total PV generation & battery discharge 2
  38.         unique_id: sg_total_pv_gen_battery_discharge_2
  39.         device_address: !secret sungrow_modbus_slave_inv2
  40.         address: 5003 # reg 5004
  41.         input_type: input
  42.         data_type: uint32
  43.         swap: word
  44.         unit_of_measurement: kWh
  45.         precision: 1
  46.         device_class: energy
  47.         state_class: total
  48.         scale: 0.1
  49.         scan_interval: 600
  50.  
  51.       - name: Inverter temperature 2
  52.         unique_id: sg_inverter_temperature_2
  53.         device_address: !secret sungrow_modbus_slave_inv2
  54.         address: 5007 # reg 5008
  55.         input_type: input
  56.         data_type: int16
  57.         precision: 1
  58.         unit_of_measurement: °C
  59.         device_class: Temperature
  60.         state_class: measurement
  61.         scale: 0.1
  62.         scan_interval: 10
  63.  
  64.       - name: MPPT1 voltage 2
  65.         unique_id: sg_mppt1_voltage_2
  66.         device_address: !secret sungrow_modbus_slave_inv2
  67.         address: 5010 # reg 5011
  68.         input_type: input
  69.         data_type: uint16
  70.         precision: 1
  71.         unit_of_measurement: V
  72.         device_class: Voltage
  73.         state_class: measurement
  74.         scale: 0.1
  75.         scan_interval: 10
  76.  
  77.       - name: MPPT1 current 2
  78.         unique_id: sg_mppt1_current_2
  79.         device_address: !secret sungrow_modbus_slave_inv2
  80.         address: 5011 # reg 5012
  81.         input_type: input
  82.         data_type: uint16
  83.         precision: 2
  84.         unit_of_measurement: A
  85.         device_class: Current
  86.         state_class: measurement
  87.         scale: 0.1
  88.         scan_interval: 10
  89.  
  90.       - name: MPPT2 voltage 2
  91.         unique_id: sg_mppt2_voltage_2
  92.         device_address: !secret sungrow_modbus_slave_inv2
  93.         address: 5012 # reg 5013
  94.         input_type: input
  95.         data_type: uint16
  96.         precision: 1
  97.         unit_of_measurement: V
  98.         device_class: Voltage
  99.         state_class: measurement
  100.         scale: 0.1
  101.         scan_interval: 10
  102.  
  103.       - name: MPPT2 current 2
  104.         unique_id: sg_mppt2_current_2
  105.         device_address: !secret sungrow_modbus_slave_inv2
  106.         address: 5013 # reg 5014
  107.         input_type: input
  108.         data_type: uint16
  109.         precision: 2
  110.         unit_of_measurement: A
  111.         device_class: Current
  112.         state_class: measurement
  113.         scale: 0.1
  114.         scan_interval: 10
  115.  
  116.       - name: Total DC power 2
  117.         unique_id: sg_total_dc_power_2
  118.         device_address: !secret sungrow_modbus_slave_inv2
  119.         address: 5016 # reg 5017
  120.         input_type: input
  121.         data_type: uint32
  122.         swap: word
  123.         precision: 0
  124.         unit_of_measurement: W
  125.         device_class: power
  126.         state_class: measurement
  127.         scale: 1
  128.         scan_interval: 10
  129.  
  130.       - name: Phase A voltage 2
  131.         unique_id: sg_phase_a_voltage_2
  132.         device_address: !secret sungrow_modbus_slave_inv2
  133.         address: 5018 # reg: 5019
  134.         input_type: input
  135.         data_type: uint16
  136.         precision: 1
  137.         unit_of_measurement: V
  138.         device_class: Voltage
  139.         state_class: measurement
  140.         scale: 0.1
  141.         scan_interval: 10
  142.  
  143.       - name: Phase B voltage 2
  144.         unique_id: sg_phase_b_voltage_2
  145.         device_address: !secret sungrow_modbus_slave_inv2
  146.         address: 5019 # reg: 5020
  147.         input_type: input
  148.         data_type: uint16
  149.         precision: 1
  150.         unit_of_measurement: V
  151.         device_class: Voltage
  152.         state_class: measurement
  153.         scale: 0.1
  154.         scan_interval: 10
  155.  
  156.       - name: Phase C voltage 2
  157.         unique_id: sg_phase_c_voltage_2
  158.         device_address: !secret sungrow_modbus_slave_inv2
  159.         address: 5020 # reg: 5021
  160.         input_type: input
  161.         data_type: uint16
  162.         precision: 1
  163.         unit_of_measurement: V
  164.         device_class: Voltage
  165.         state_class: measurement
  166.         scale: 0.1
  167.         scan_interval: 10
  168.  
  169.       - name: Grid frequency 2
  170.         unique_id: sg_grid_frequency_2
  171.         device_address: !secret sungrow_modbus_slave_inv2
  172.         address: 5035 # reg 5036
  173.         input_type: input
  174.         data_type: uint16
  175.         precision: 2
  176.         unit_of_measurement: "Hz"
  177.         device_class: frequency
  178.         state_class: measurement
  179.         scale: 0.1
  180.         scan_interval: 10
  181.  
  182.       - name: Reactive power 2
  183.         unique_id: sg_reactive_power_2
  184.         device_address: !secret sungrow_modbus_slave_inv2
  185.         address: 5032 # reg 5033
  186.         input_type: input
  187.         data_type: int32
  188.         swap: word
  189.         precision: 0
  190.         unit_of_measurement: W
  191.         device_class: power
  192.         state_class: measurement
  193.         scale: 1
  194.         scan_interval: 10
  195.  
  196.       - name: Power factor 2
  197.         unique_id: sg_power_factor_2
  198.         device_address: !secret sungrow_modbus_slave_inv2
  199.         address: 5034 # reg 5035
  200.         input_type: input
  201.         data_type: int16
  202.         precision: 3
  203.         unit_of_measurement: "%"
  204.         device_class: power_factor
  205.         state_class: measurement
  206.         scale: 0.001
  207.         scan_interval: 10
  208.  
  209.       #https://www.photovoltaikforum.com/thread/166134-daten-lesen-vom-sungrow-wechselrichtern-modbus/?pageNo=13
  210.       #Meter Active Power: 5601-5602 S32 W (Energiezähler Wirkleistung)
  211.       #Meter Phase A Active Power: 5603-5604 S32 W (Stromzähler Phase A Wirkleistung)
  212.       #Meter Phase B Active Power: 5605-5606 S32 W (Stromzähler Phase B Wirkleistung)
  213.       #Meter Phase C Active Power: 5607-5608 S32 W (Stromzähler Phase C Wirkleistung)
  214.       - name: Meter active power raw 2
  215.         unique_id: sg_meter_active_power_raw_2
  216.         device_address: !secret sungrow_modbus_slave_inv2
  217.         address: 5600 # reg 5601
  218.         input_type: input
  219.         data_type: int32
  220.         swap: word
  221.         precision: 0
  222.         unit_of_measurement: W
  223.         device_class: power
  224.         state_class: measurement
  225.         scale: 1
  226.         scan_interval: 10
  227.  
  228.       - name: Meter phase A active power raw 2
  229.         unique_id: sg_meter_phase_a_active_power_raw_2
  230.         device_address: !secret sungrow_modbus_slave_inv2
  231.         address: 5602 # reg 5603
  232.         input_type: input
  233.         data_type: int32
  234.         swap: word
  235.         precision: 0
  236.         unit_of_measurement: W
  237.         device_class: power
  238.         state_class: measurement
  239.         scale: 1
  240.         scan_interval: 10
  241.  
  242.       - name: Meter phase B active power raw 2
  243.         unique_id: sg_meter_phase_b_active_power_raw_2
  244.         device_address: !secret sungrow_modbus_slave_inv2
  245.         address: 5604 # reg 5605
  246.         input_type: input
  247.         data_type: int32
  248.         swap: word
  249.         precision: 0
  250.         unit_of_measurement: W
  251.         device_class: power
  252.         state_class: measurement
  253.         scale: 1
  254.         scan_interval: 10
  255.  
  256.       - name: Meter phase C active power raw 2
  257.         unique_id: sg_meter_phase_c_active_power_raw_2
  258.         device_address: !secret sungrow_modbus_slave_inv2
  259.         address: 5606 # reg 5607
  260.         input_type: input
  261.         data_type: int32
  262.         swap: word
  263.         precision: 0
  264.         unit_of_measurement: W
  265.         device_class: power
  266.         state_class: measurement
  267.         scale: 1
  268.         scan_interval: 10
  269.  
  270.       - name: BDC rated power 2
  271.         unique_id: sg_bdc_rated_power_2
  272.         device_address: !secret sungrow_modbus_slave_inv2
  273.         address: 5627 # reg 5628
  274.         input_type: input
  275.         data_type: uint16
  276.         unit_of_measurement: "W"
  277.         device_class: power
  278.         state_class: measurement
  279.         scale: 100
  280.         scan_interval: 600
  281.  
  282.       - name: BMS max. charging current 2
  283.         unique_id: sg_bms_max_charging_current_2
  284.         device_address: !secret sungrow_modbus_slave_inv2
  285.         address: 5634 # reg 5635
  286.         input_type: input
  287.         data_type: uint16
  288.         precision: 0
  289.         unit_of_measurement: A
  290.         device_class: Current
  291.         state_class: measurement
  292.         scale: 1
  293.         scan_interval: 60
  294.  
  295.       - name: BMS max. discharging current 2
  296.         unique_id: sg_bms_max_discharging_current_2
  297.         device_address: !secret sungrow_modbus_slave_inv2
  298.         address: 5635 # reg 5636
  299.         input_type: input
  300.         data_type: uint16
  301.         precision: 0
  302.         unit_of_measurement: A
  303.         device_class: Current
  304.         state_class: measurement
  305.         scale: 1
  306.         scan_interval: 60
  307.  
  308.       #https://www.photovoltaikforum.com/thread/166134-daten-lesen-vom-sungrow-wechselrichtern-modbus/?pageNo=13
  309.       #Phase A Backup Power: 5723 S16 W (Backup Leistung Phase A)
  310.       #Phase B Backup Power: 5724 S16 W (Backup Leistung Phase B)
  311.       #Phase C Backup Power: 5725 S16 W (Backup Leistung Phase C)
  312.       - name: Total backup power 2
  313.         device_address: !secret sungrow_modbus_slave_inv2
  314.         unique_id: sg_total_backup_power_2
  315.         address: 5725 # reg 5726
  316.         input_type: input
  317.         data_type: int16
  318.         precision: 0
  319.         unit_of_measurement: W
  320.         device_class: power
  321.         state_class: measurement
  322.         scale: 1
  323.         scan_interval: 10
  324.  
  325.       - name: Backup phase A power 2
  326.         unique_id: sg_backup_phase_a_power_2
  327.         device_address: !secret sungrow_modbus_slave_inv2
  328.         address: 5722 # reg 5723
  329.         input_type: input
  330.         data_type: int16
  331.         precision: 0
  332.         unit_of_measurement: W
  333.         device_class: power
  334.         state_class: measurement
  335.         scale: 1
  336.         scan_interval: 10
  337.  
  338.       - name: Backup phase B power 2
  339.         unique_id: sg_backup_phase_b_power_2
  340.         device_address: !secret sungrow_modbus_slave_inv2
  341.         address: 5723 # reg 5724
  342.         input_type: input
  343.         data_type: int16
  344.         precision: 0
  345.         unit_of_measurement: W
  346.         device_class: power
  347.         state_class: measurement
  348.         scale: 1
  349.         scan_interval: 10
  350.  
  351.       - name: Backup phase C power 2
  352.         unique_id: sg_backup_phase_c_power_2
  353.         device_address: !secret sungrow_modbus_slave_inv2
  354.         address: 5724 # reg 5725
  355.         input_type: input
  356.         data_type: int16
  357.         precision: 0
  358.         unit_of_measurement: W
  359.         device_class: power
  360.         state_class: measurement
  361.         scale: 1
  362.         scan_interval: 10
  363.  
  364.       # Start monthly PV generation
  365.       - name: Monthly PV generation (01 January) 2
  366.         unique_id: sg_monthly_pv_generation_01_january_2
  367.         device_address: !secret sungrow_modbus_slave_inv2
  368.         address: 6226 # reg 6227
  369.         input_type: input
  370.         data_type: uint16
  371.         precision: 1
  372.         unit_of_measurement: kWh
  373.         device_class: energy
  374.         state_class: total_increasing
  375.         scale: 0.1
  376.         scan_interval: 600
  377.  
  378.       - name: Monthly PV generation (02 February) 2
  379.         unique_id: sg_monthly_pv_generation_02_february_2
  380.         device_address: !secret sungrow_modbus_slave_inv2
  381.         address: 6227 # reg 6228
  382.         input_type: input
  383.         data_type: uint16
  384.         precision: 1
  385.         unit_of_measurement: kWh
  386.         device_class: energy
  387.         state_class: total_increasing
  388.         scale: 0.1
  389.         scan_interval: 600
  390.  
  391.       - name: Monthly PV generation (03 March) 2
  392.         unique_id: sg_monthly_pv_generation_03_march_2
  393.         device_address: !secret sungrow_modbus_slave_inv2
  394.         address: 6228 # reg 6229
  395.         input_type: input
  396.         data_type: uint16
  397.         precision: 1
  398.         unit_of_measurement: kWh
  399.         device_class: energy
  400.         state_class: total_increasing
  401.         scale: 0.1
  402.         scan_interval: 600
  403.  
  404.       - name: Monthly PV generation (04 April) 2
  405.         unique_id: sg_monthly_pv_generation_04_april_2
  406.         device_address: !secret sungrow_modbus_slave_inv2
  407.         address: 6229 # reg 6230
  408.         input_type: input
  409.         data_type: uint16
  410.         precision: 1
  411.         unit_of_measurement: kWh
  412.         device_class: energy
  413.         state_class: total_increasing
  414.         scale: 0.1
  415.         scan_interval: 600
  416.  
  417.       - name: Monthly PV generation (05 May) 2
  418.         unique_id: sg_monthly_pv_generation_05_may_2
  419.         device_address: !secret sungrow_modbus_slave_inv2
  420.         address: 6230 # reg 6231
  421.         input_type: input
  422.         data_type: uint16
  423.         precision: 1
  424.         unit_of_measurement: kWh
  425.         device_class: energy
  426.         state_class: total_increasing
  427.         scale: 0.1
  428.         scan_interval: 600
  429.  
  430.       - name: Monthly PV generation (06 June) 2
  431.         unique_id: sg_monthly_pv_generation_06_june_2
  432.         device_address: !secret sungrow_modbus_slave_inv2
  433.         address: 6231 # reg 6232
  434.         input_type: input
  435.         data_type: uint16
  436.         precision: 1
  437.         unit_of_measurement: kWh
  438.         device_class: energy
  439.         state_class: total_increasing
  440.         scale: 0.1
  441.         scan_interval: 600
  442.  
  443.       - name: Monthly PV generation (07 July) 2
  444.         unique_id: sg_monthly_pv_generation_07_july_2
  445.         device_address: !secret sungrow_modbus_slave_inv2
  446.         address: 6232 # reg 6233
  447.         input_type: input
  448.         data_type: uint16
  449.         precision: 1
  450.         unit_of_measurement: kWh
  451.         device_class: energy
  452.         state_class: total_increasing
  453.         scale: 0.1
  454.         scan_interval: 600
  455.  
  456.       - name: Monthly PV generation (08 August) 2
  457.         unique_id: sg_monthly_pv_generation_08_august_2
  458.         device_address: !secret sungrow_modbus_slave_inv2
  459.         address: 6233 # reg 6234
  460.         input_type: input
  461.         data_type: uint16
  462.         precision: 1
  463.         unit_of_measurement: kWh
  464.         device_class: energy
  465.         state_class: total_increasing
  466.         scale: 0.1
  467.         scan_interval: 600
  468.  
  469.       - name: Monthly PV generation (09 September) 2
  470.         unique_id: sg_monthly_pv_generation_09_september_2
  471.         device_address: !secret sungrow_modbus_slave_inv2
  472.         address: 6234 # reg 6235
  473.         input_type: input
  474.         data_type: uint16
  475.         precision: 1
  476.         unit_of_measurement: kWh
  477.         device_class: energy
  478.         state_class: total_increasing
  479.         scale: 0.1
  480.         scan_interval: 600
  481.  
  482.       - name: Monthly PV generation (10 October) 2
  483.         unique_id: sg_monthly_pv_generation_10_october_2
  484.         device_address: !secret sungrow_modbus_slave_inv2
  485.         address: 6235 # reg 6236
  486.         input_type: input
  487.         data_type: uint16
  488.         precision: 1
  489.         unit_of_measurement: kWh
  490.         device_class: energy
  491.         state_class: total_increasing
  492.         scale: 0.1
  493.         scan_interval: 600
  494.  
  495.       - name: Monthly PV generation (11 November) 2
  496.         unique_id: sg_monthly_pv_generation_11_november_2
  497.         device_address: !secret sungrow_modbus_slave_inv2
  498.         address: 6236 # reg 6237
  499.         input_type: input
  500.         data_type: uint16
  501.         precision: 1
  502.         unit_of_measurement: kWh
  503.         device_class: energy
  504.         state_class: total_increasing
  505.         scale: 0.1
  506.         scan_interval: 600
  507.  
  508.       - name: Monthly PV generation (12 December) 2
  509.         unique_id: sg_monthly_pv_generation_12_december_2
  510.         device_address: !secret sungrow_modbus_slave_inv2
  511.         address: 6237 # reg 6238
  512.         input_type: input
  513.         data_type: uint16
  514.         precision: 1
  515.         unit_of_measurement: kWh
  516.         device_class: energy
  517.         state_class: total_increasing
  518.         scale: 0.1
  519.         scan_interval: 600
  520.       # End monthly PV generation
  521.  
  522.       # Start yearly pv generation
  523.       - name: Yearly PV generation (2019) 2
  524.         unique_id: sg_yearly_pv_generation_2019_2
  525.         device_address: !secret sungrow_modbus_slave_inv2
  526.         address: 6257 # reg 6258
  527.         input_type: input
  528.         data_type: uint32
  529.         swap: word
  530.         precision: 1
  531.         unit_of_measurement: kWh
  532.         device_class: energy
  533.         state_class: total_increasing
  534.         scale: 0.1
  535.         scan_interval: 600
  536.  
  537.       - name: Yearly PV generation (2020) 2
  538.         unique_id: sg_yearly_pv_generation_2020_2
  539.         device_address: !secret sungrow_modbus_slave_inv2
  540.         address: 6259 # reg 6260
  541.         input_type: input
  542.         data_type: uint32
  543.         swap: word
  544.         precision: 1
  545.         unit_of_measurement: kWh
  546.         device_class: energy
  547.         state_class: total_increasing
  548.         scale: 0.1
  549.         scan_interval: 600
  550.  
  551.       - name: Yearly PV generation (2021) 2
  552.         unique_id: sg_yearly_pv_generation_2021_2
  553.         device_address: !secret sungrow_modbus_slave_inv2
  554.         address: 6261 # reg 6262
  555.         input_type: input
  556.         data_type: uint32
  557.         swap: word
  558.         precision: 1
  559.         unit_of_measurement: kWh
  560.         device_class: energy
  561.         state_class: total_increasing
  562.         scale: 0.1
  563.         scan_interval: 600
  564.  
  565.       - name: Yearly PV generation (2022) 2
  566.         unique_id: sg_yearly_pv_generation_2022
  567.         device_address: !secret sungrow_modbus_slave_inv2
  568.         address: 6263 # reg 6264
  569.         input_type: input
  570.         data_type: uint32
  571.         swap: word
  572.         precision: 1
  573.         unit_of_measurement: kWh
  574.         device_class: energy
  575.         state_class: total_increasing
  576.         scale: 0.1
  577.         scan_interval: 600
  578.  
  579.       - name: Yearly PV generation (2023) 2
  580.         unique_id: sg_yearly_pv_generation_2023_2
  581.         device_address: !secret sungrow_modbus_slave_inv2
  582.         address: 6265 # reg 6266
  583.         input_type: input
  584.         data_type: uint32
  585.         swap: word
  586.         precision: 1
  587.         unit_of_measurement: kWh
  588.         device_class: energy
  589.         state_class: total_increasing
  590.         scale: 0.1
  591.         scan_interval: 600
  592.  
  593.       - name: Yearly PV generation (2024) 2
  594.         unique_id: sg_yearly_pv_generation_2024_2
  595.         device_address: !secret sungrow_modbus_slave_inv2
  596.         address: 6267 # reg 6268
  597.         input_type: input
  598.         data_type: uint32
  599.         swap: word
  600.         precision: 1
  601.         unit_of_measurement: kWh
  602.         device_class: energy
  603.         state_class: total_increasing
  604.         scale: 0.1
  605.         scan_interval: 600
  606.  
  607.       - name: Yearly PV generation (2025) 2
  608.         unique_id: sg_yearly_pv_generation_2025_2
  609.         device_address: !secret sungrow_modbus_slave_inv2
  610.         address: 6269 # reg 6270
  611.         input_type: input
  612.         data_type: uint32
  613.         swap: word
  614.         precision: 1
  615.         unit_of_measurement: kWh
  616.         device_class: energy
  617.         state_class: total_increasing
  618.         scale: 0.1
  619.         scan_interval: 600
  620.  
  621.       - name: Yearly PV generation (2026) 2
  622.         unique_id: sg_yearly_pv_generation_2026_2
  623.         device_address: !secret sungrow_modbus_slave_inv2
  624.         address: 6271 # reg 6272
  625.         input_type: input
  626.         data_type: uint32
  627.         swap: word
  628.         precision: 1
  629.         unit_of_measurement: kWh
  630.         device_class: energy
  631.         state_class: total_increasing
  632.         scale: 0.1
  633.         scan_interval: 600
  634.  
  635.       - name: Yearly PV generation (2027) 2
  636.         unique_id: sg_yearly_pv_generation_2027_2
  637.         device_address: !secret sungrow_modbus_slave_inv2
  638.         address: 6273 # reg 6274
  639.         input_type: input
  640.         data_type: uint32
  641.         swap: word
  642.         precision: 1
  643.         unit_of_measurement: kWh
  644.         device_class: energy
  645.         state_class: total_increasing
  646.         scale: 0.1
  647.         scan_interval: 600
  648.  
  649.       - name: Yearly PV generation (2028) 2
  650.         unique_id: sg_yearly_pv_generation_2028_2
  651.         device_address: !secret sungrow_modbus_slave_inv2
  652.         address: 6275 # reg 6276
  653.         input_type: input
  654.         data_type: uint32
  655.         swap: word
  656.         precision: 1
  657.         unit_of_measurement: kWh
  658.         device_class: energy
  659.         state_class: total_increasing
  660.         scale: 0.1
  661.         scan_interval: 600
  662.  
  663.       - name: Yearly PV generation (2029) 2
  664.         unique_id: sg_yearly_pv_generation_2029_2
  665.         device_address: !secret sungrow_modbus_slave_inv2
  666.         address: 6277 # reg 6278
  667.         input_type: input
  668.         data_type: uint32
  669.         swap: word
  670.         precision: 1
  671.         unit_of_measurement: kWh
  672.         device_class: energy
  673.         state_class: total_increasing
  674.         scale: 0.1
  675.         scan_interval: 600
  676.       # End yearly pv generation
  677.  
  678.       # Start monthly export
  679.       - name: Monthly export (01 January) 2
  680.         unique_id: sg_monthly_export_01_january_2
  681.         device_address: !secret sungrow_modbus_slave_inv2
  682.         address: 6595 # reg 6596
  683.         input_type: input
  684.         data_type: uint16
  685.         precision: 1
  686.         unit_of_measurement: kWh
  687.         device_class: energy
  688.         state_class: total_increasing
  689.         scale: 0.1
  690.         scan_interval: 600
  691.  
  692.       - name: Monthly export (02 February) 2
  693.         unique_id: sg_monthly_export_02_february_2
  694.         device_address: !secret sungrow_modbus_slave_inv2
  695.         address: 6596 # reg 6597
  696.         input_type: input
  697.         data_type: uint16
  698.         precision: 1
  699.         unit_of_measurement: kWh
  700.         device_class: energy
  701.         state_class: total_increasing
  702.         scale: 0.1
  703.         scan_interval: 600
  704.  
  705.       - name: Monthly export (03 March) 2
  706.         unique_id: sg_monthly_export_03_march_2
  707.         device_address: !secret sungrow_modbus_slave_inv2
  708.         address: 6597 # reg 6598
  709.         input_type: input
  710.         data_type: uint16
  711.         precision: 1
  712.         unit_of_measurement: kWh
  713.         device_class: energy
  714.         state_class: total_increasing
  715.         scale: 0.1
  716.         scan_interval: 600
  717.  
  718.       - name: Monthly export (04 April) 2
  719.         unique_id: sg_monthly_export_04_april_2
  720.         device_address: !secret sungrow_modbus_slave_inv2
  721.         address: 6598 # reg 6599
  722.         input_type: input
  723.         data_type: uint16
  724.         precision: 1
  725.         unit_of_measurement: kWh
  726.         device_class: energy
  727.         state_class: total_increasing
  728.         scale: 0.1
  729.         scan_interval: 600
  730.  
  731.       - name: Monthly export (05 May) 2
  732.         unique_id: sg_monthly_export_05_may_2
  733.         device_address: !secret sungrow_modbus_slave_inv2
  734.         address: 6599 # reg 6600
  735.         input_type: input
  736.         data_type: uint16
  737.         precision: 1
  738.         unit_of_measurement: kWh
  739.         device_class: energy
  740.         state_class: total_increasing
  741.         scale: 0.1
  742.         scan_interval: 600
  743.  
  744.       - name: Monthly export (06 June) 2
  745.         unique_id: sg_monthly_export_06_june_2
  746.         device_address: !secret sungrow_modbus_slave_inv2
  747.         address: 6600 # reg 6601
  748.         input_type: input
  749.         data_type: uint16
  750.         precision: 1
  751.         unit_of_measurement: kWh
  752.         device_class: energy
  753.         state_class: total_increasing
  754.         scale: 0.1
  755.         scan_interval: 600
  756.  
  757.       - name: Monthly export (07 July) 2
  758.         unique_id: sg_monthly_export_07_july_2
  759.         device_address: !secret sungrow_modbus_slave_inv2
  760.         address: 6601 # reg 6602
  761.         input_type: input
  762.         data_type: uint16
  763.         precision: 1
  764.         unit_of_measurement: kWh
  765.         device_class: energy
  766.         state_class: total_increasing
  767.         scale: 0.1
  768.         scan_interval: 600
  769.  
  770.       - name: Monthly export (08 August) 2
  771.         unique_id: sg_monthly_export_08_august_2
  772.         device_address: !secret sungrow_modbus_slave_inv2
  773.         address: 6602 # reg 6603
  774.         input_type: input
  775.         data_type: uint16
  776.         precision: 1
  777.         unit_of_measurement: kWh
  778.         device_class: energy
  779.         state_class: total_increasing
  780.         scale: 0.1
  781.         scan_interval: 600
  782.  
  783.       - name: Monthly export (09 September) 2
  784.         unique_id: sg_monthly_export_09_september_2
  785.         device_address: !secret sungrow_modbus_slave_inv2
  786.         address: 6603 # reg 6604
  787.         input_type: input
  788.         data_type: uint16
  789.         precision: 1
  790.         unit_of_measurement: kWh
  791.         device_class: energy
  792.         state_class: total_increasing
  793.         scale: 0.1
  794.         scan_interval: 600
  795.  
  796.       - name: Monthly export (10 October) 2
  797.         unique_id: sg_monthly_export_10_october_2
  798.         device_address: !secret sungrow_modbus_slave_inv2
  799.         address: 6604 # reg 6605
  800.         input_type: input
  801.         data_type: uint16
  802.         precision: 1
  803.         unit_of_measurement: kWh
  804.         device_class: energy
  805.         state_class: total_increasing
  806.         scale: 0.1
  807.         scan_interval: 600
  808.  
  809.       - name: Monthly export (11 November) 2
  810.         unique_id: sg_monthly_export_11_november_2
  811.         device_address: !secret sungrow_modbus_slave_inv2
  812.         address: 6605 # reg 6606
  813.         input_type: input
  814.         data_type: uint16
  815.         precision: 1
  816.         unit_of_measurement: kWh
  817.         device_class: energy
  818.         state_class: total_increasing
  819.         scale: 0.1
  820.         scan_interval: 600
  821.  
  822.       - name: Monthly export (12 December) 2
  823.         unique_id: sg_monthly_export_12_december_2
  824.         device_address: !secret sungrow_modbus_slave_inv2
  825.         address: 6606 # reg 6607
  826.         input_type: input
  827.         data_type: uint16
  828.         precision: 1
  829.         unit_of_measurement: kWh
  830.         device_class: energy
  831.         state_class: total_increasing
  832.         scale: 0.1
  833.         scan_interval: 600
  834.       # End monthly export
  835.  
  836.       # Start yearly export energy from PV
  837.       - name: Yearly Export (2019) 2
  838.         unique_id: sg_yearly_export_2019_2
  839.         device_address: !secret sungrow_modbus_slave_inv2
  840.         address: 6615 # reg 6616
  841.         input_type: input
  842.         data_type: uint32
  843.         swap: word
  844.         precision: 1
  845.         unit_of_measurement: kWh
  846.         device_class: energy
  847.         state_class: total
  848.         scale: 0.1
  849.         scan_interval: 600
  850.  
  851.       - name: Yearly Export (2020) 2
  852.         unique_id: sg_yearly_export_2020_2
  853.         device_address: !secret sungrow_modbus_slave_inv2
  854.         address: 6617 # reg 6618
  855.         input_type: input
  856.         data_type: uint32
  857.         swap: word
  858.         precision: 1
  859.         unit_of_measurement: kWh
  860.         device_class: energy
  861.         state_class: total
  862.         scale: 0.1
  863.         scan_interval: 600
  864.  
  865.       - name: Yearly Export (2021) 2
  866.         unique_id: sg_yearly_export_2021_2
  867.         device_address: !secret sungrow_modbus_slave_inv2
  868.         address: 6619 # reg 6620
  869.         input_type: input
  870.         data_type: uint32
  871.         swap: word
  872.         precision: 1
  873.         unit_of_measurement: kWh
  874.         device_class: energy
  875.         state_class: total
  876.         scale: 0.1
  877.         scan_interval: 600
  878.  
  879.       - name: Yearly Export (2022) 2
  880.         unique_id: sg_yearly_export_2022
  881.         device_address: !secret sungrow_modbus_slave_inv2
  882.         address: 6621 # reg 6622
  883.         input_type: input
  884.         data_type: uint32
  885.         swap: word
  886.         precision: 1
  887.         unit_of_measurement: kWh
  888.         device_class: energy
  889.         state_class: total
  890.         scale: 0.1
  891.         scan_interval: 600
  892.  
  893.       - name: Yearly Export (2023) 2
  894.         unique_id: sg_yearly_export_2023_2
  895.         device_address: !secret sungrow_modbus_slave_inv2
  896.         address: 6623 # reg 6624
  897.         input_type: input
  898.         data_type: uint32
  899.         swap: word
  900.         precision: 1
  901.         unit_of_measurement: kWh
  902.         device_class: energy
  903.         state_class: total
  904.         scale: 0.1
  905.         scan_interval: 600
  906.  
  907.       - name: Yearly Export (2024) 2
  908.         unique_id: sg_yearly_export_2024_2
  909.         device_address: !secret sungrow_modbus_slave_inv2
  910.         address: 6625 # reg 6626
  911.         input_type: input
  912.         data_type: uint32
  913.         swap: word
  914.         precision: 1
  915.         unit_of_measurement: kWh
  916.         device_class: energy
  917.         state_class: total
  918.         scale: 0.1
  919.         scan_interval: 600
  920.  
  921.       - name: Yearly Export (2025) 2
  922.         unique_id: sg_yearly_export_2025_2
  923.         device_address: !secret sungrow_modbus_slave_inv2
  924.         address: 6627 # reg 6628
  925.         input_type: input
  926.         data_type: uint32
  927.         swap: word
  928.         precision: 1
  929.         unit_of_measurement: kWh
  930.         device_class: energy
  931.         state_class: total
  932.         scale: 0.1
  933.         scan_interval: 600
  934.  
  935.       - name: Yearly Export (2026) 2
  936.         unique_id: sg_yearly_export_2026_2
  937.         device_address: !secret sungrow_modbus_slave_inv2
  938.         address: 6629 # reg 6630
  939.         input_type: input
  940.         data_type: uint32
  941.         swap: word
  942.         precision: 1
  943.         unit_of_measurement: kWh
  944.         device_class: energy
  945.         state_class: total
  946.         scale: 0.1
  947.         scan_interval: 600
  948.  
  949.       - name: Yearly Export (2027) 2
  950.         unique_id: sg_yearly_export_2027_2
  951.         device_address: !secret sungrow_modbus_slave_inv2
  952.         address: 6631 # reg 6632
  953.         input_type: input
  954.         data_type: uint32
  955.         swap: word
  956.         precision: 1
  957.         unit_of_measurement: kWh
  958.         device_class: energy
  959.         state_class: total
  960.         scale: 0.1
  961.         scan_interval: 600
  962.  
  963.       - name: Yearly Export (2028) 2
  964.         unique_id: sg_yearly_export_2028_2
  965.         device_address: !secret sungrow_modbus_slave_inv2
  966.         address: 6633 # reg 6634
  967.         input_type: input
  968.         data_type: uint32
  969.         swap: word
  970.         precision: 1
  971.         unit_of_measurement: kWh
  972.         device_class: energy
  973.         state_class: total
  974.         scale: 0.1
  975.         scan_interval: 600
  976.       # End yearly export energy from PV
  977.  
  978.       - name: System state 2
  979.         unique_id: sg_system_state_2
  980.         device_address: !secret sungrow_modbus_slave_inv2
  981.         address: 12999 # reg 13000
  982.         input_type: input
  983.         data_type: uint16
  984.         precision: 0
  985.         scale: 1
  986.         state_class: measurement
  987.         scan_interval: 10
  988.  
  989.       # register running state is not available for certain SH*RS inverters
  990.       # template sensors are used to determine the states based on other sensors
  991.       - name: Running state 2
  992.         unique_id: sg_running_state_2
  993.         device_address: !secret sungrow_modbus_slave_inv2
  994.         address: 13000 # reg 13001
  995.         input_type: input
  996.         data_type: uint16
  997.         precision: 0
  998.         state_class: measurement
  999.         scale: 1
  1000.         scan_interval: 10
  1001.  
  1002.       - name: Daily PV generation 2
  1003.         unique_id: sg_daily_pv_generation_2
  1004.         device_address: !secret sungrow_modbus_slave_inv2
  1005.         address: 13001 # reg 13002
  1006.         input_type: input
  1007.         data_type: uint16
  1008.         precision: 1
  1009.         unit_of_measurement: kWh
  1010.         device_class: energy
  1011.         state_class: total_increasing
  1012.         scale: 0.1
  1013.         scan_interval: 600
  1014.  
  1015.       - name: Total PV generation 2
  1016.         unique_id: sg_total_pv_generation_2
  1017.         device_address: !secret sungrow_modbus_slave_inv2
  1018.         address: 13002 # reg 13003
  1019.         input_type: input
  1020.         data_type: uint32
  1021.         swap: word
  1022.         precision: 1
  1023.         unit_of_measurement: kWh
  1024.         device_class: energy
  1025.         state_class: total
  1026.         scale: 0.1
  1027.         scan_interval: 600
  1028.  
  1029.       - name: Daily exported energy from PV 2
  1030.         unique_id: sg_daily_exported_energy_from_PV_2
  1031.         device_address: !secret sungrow_modbus_slave_inv2
  1032.         address: 13004 # reg 13005
  1033.         input_type: input
  1034.         data_type: uint16
  1035.         precision: 1
  1036.         unit_of_measurement: kWh
  1037.         device_class: energy
  1038.         state_class: total_increasing
  1039.         scale: 0.1
  1040.         scan_interval: 600
  1041.  
  1042.       - name: Total exported energy from PV 2
  1043.         unique_id: sg_total_exported_energy_from_pv_2
  1044.         device_address: !secret sungrow_modbus_slave_inv2
  1045.         address: 13005 # reg 13006
  1046.         input_type: input
  1047.         data_type: uint32
  1048.         swap: word
  1049.         precision: 1
  1050.         unit_of_measurement: kWh
  1051.         device_class: energy
  1052.         state_class: total
  1053.         scale: 0.1
  1054.         scan_interval: 600
  1055.  
  1056.       - name: Load power 2
  1057.         unique_id: sg_load_power_2
  1058.         device_address: !secret sungrow_modbus_slave_inv2
  1059.         address: 13007 # reg 13008
  1060.         input_type: input
  1061.         data_type: int32
  1062.         swap: word
  1063.         precision: 0
  1064.         unit_of_measurement: W
  1065.         device_class: power
  1066.         state_class: measurement
  1067.         scale: 1
  1068.         scan_interval: 10
  1069.  
  1070.       # this value returns a positive value when exporting and a negative value when importing power
  1071.       - name: Export power raw 2
  1072.         unique_id: sg_battery_export_power_raw_2
  1073.         device_address: !secret sungrow_modbus_slave_inv2
  1074.         address: 13009 # reg 13010
  1075.         input_type: input
  1076.         data_type: int32
  1077.         swap: word
  1078.         precision: 0
  1079.         unit_of_measurement: W
  1080.         device_class: power
  1081.         state_class: measurement
  1082.         scale: 1
  1083.         scan_interval: 10
  1084.  
  1085.       - name: Daily battery charge from PV 2
  1086.         unique_id: sg_daily_battery_charge_from_pv_2
  1087.         device_address: !secret sungrow_modbus_slave_inv2
  1088.         address: 13011 # reg 13012
  1089.         input_type: input
  1090.         data_type: uint16
  1091.         precision: 1
  1092.         unit_of_measurement: kWh
  1093.         device_class: energy
  1094.         state_class: total_increasing
  1095.         scale: 0.1
  1096.         scan_interval: 600
  1097.  
  1098.       - name: Total battery charge from PV 2
  1099.         unique_id: sg_total_battery_charge_from_pv_2
  1100.         device_address: !secret sungrow_modbus_slave_inv2
  1101.         address: 13012 # reg 13013
  1102.         input_type: input
  1103.         data_type: uint32
  1104.         swap: word
  1105.         precision: 1
  1106.         unit_of_measurement: kWh
  1107.         device_class: energy
  1108.         state_class: total
  1109.         scale: 0.1
  1110.         scan_interval: 600
  1111.  
  1112.       - name: Daily direct energy consumption 2
  1113.         unique_id: sg_daily_direct_energy_consumption_2
  1114.         device_address: !secret sungrow_modbus_slave_inv2
  1115.         address: 13016 # reg 13017
  1116.         input_type: input
  1117.         data_type: uint16
  1118.         precision: 1
  1119.         unit_of_measurement: kWh
  1120.         device_class: energy
  1121.         state_class: total_increasing
  1122.         scale: 0.1
  1123.         scan_interval: 600
  1124.  
  1125.       - name: Total direct energy consumption 2
  1126.         unique_id: sg_total_direct_energy_consumption_2
  1127.         device_address: !secret sungrow_modbus_slave_inv2
  1128.         address: 13017 # reg 13018
  1129.         input_type: input
  1130.         data_type: uint32
  1131.         swap: word
  1132.         precision: 1
  1133.         unit_of_measurement: kWh
  1134.         device_class: energy
  1135.         state_class: total
  1136.         scale: 0.1
  1137.         scan_interval: 600
  1138.  
  1139.       - name: Battery voltage 2
  1140.         unique_id: sg_battery_voltage_2
  1141.         device_address: !secret sungrow_modbus_slave_inv2
  1142.         address: 13019 # reg 13020
  1143.         input_type: input
  1144.         data_type: uint16
  1145.         precision: 0
  1146.         unit_of_measurement: V
  1147.         device_class: Voltage
  1148.         state_class: measurement
  1149.         scale: 0.1
  1150.         scan_interval: 10
  1151.  
  1152.       - name: Battery current 2
  1153.         unique_id: sg_battery_current_2
  1154.         device_address: !secret sungrow_modbus_slave_inv2
  1155.         address: 13020 # reg 13021
  1156.         input_type: input
  1157.         data_type: uint16
  1158.         precision: 1
  1159.         unit_of_measurement: A
  1160.         state_class: measurement
  1161.         device_class: Current
  1162.         scale: 0.1
  1163.         scan_interval: 10
  1164.  
  1165.       # always positive battery power
  1166.       # use binary_sensor.battery_charging_2 | discharging to retrieve the direction of the energy flow
  1167.       - name: Battery power raw 2
  1168.         unique_id: sg_battery_power_raw_2
  1169.         device_address: !secret sungrow_modbus_slave_inv2
  1170.         address: 13021 # reg 13022
  1171.         input_type: input
  1172.         data_type: uint16
  1173.         precision: 0
  1174.         unit_of_measurement: W
  1175.         device_class: power
  1176.         state_class: measurement
  1177.         scale: 1
  1178.         scan_interval: 10
  1179.  
  1180.       - name: Battery level 2
  1181.         unique_id: sg_battery_level_2
  1182.         device_address: !secret sungrow_modbus_slave_inv2
  1183.         address: 13022 # reg 13023
  1184.         input_type: input
  1185.         data_type: uint16
  1186.         precision: 1
  1187.         unit_of_measurement: "%"
  1188.         device_class: battery
  1189.         state_class: measurement
  1190.         scale: 0.1
  1191.         scan_interval: 60
  1192.  
  1193.       - name: Battery state of health 2
  1194.         unique_id: sg_battery_state_of_health_2
  1195.         device_address: !secret sungrow_modbus_slave_inv2
  1196.         address: 13023 # reg 13024
  1197.         input_type: input
  1198.         data_type: uint16
  1199.         precision: 0
  1200.         unit_of_measurement: "%"
  1201.         state_class: measurement
  1202.         scale: 0.1
  1203.         scan_interval: 600
  1204.  
  1205.       - name: Battery temperature 2
  1206.         unique_id: sg_battery_temperature_2
  1207.         device_address: !secret sungrow_modbus_slave_inv2
  1208.         address: 13024 # reg 13025
  1209.         input_type: input
  1210.         data_type: int16
  1211.         precision: 1
  1212.         unit_of_measurement: °C
  1213.         device_class: Temperature
  1214.         state_class: measurement
  1215.         scale: 0.1
  1216.         scan_interval: 60
  1217.  
  1218.       - name: Daily battery discharge 2
  1219.         unique_id: sg_daily_battery_discharge_2
  1220.         device_address: !secret sungrow_modbus_slave_inv2
  1221.         address: 13025 # reg 13026
  1222.         input_type: input
  1223.         data_type: uint16
  1224.         precision: 1
  1225.         unit_of_measurement: kWh
  1226.         device_class: energy
  1227.         state_class: total_increasing
  1228.         scale: 0.1
  1229.         scan_interval: 600
  1230.  
  1231.       - name: Total battery discharge 2
  1232.         unique_id: sg_total_battery_discharge_2
  1233.         device_address: !secret sungrow_modbus_slave_inv2
  1234.         address: 13026 # reg 13027
  1235.         input_type: input
  1236.         data_type: uint32
  1237.         swap: word
  1238.         precision: 1
  1239.         unit_of_measurement: kWh
  1240.         device_class: energy
  1241.         state_class: total
  1242.         scale: 0.1
  1243.         scan_interval: 600
  1244.  
  1245.       - name: Phase A current 2
  1246.         unique_id: sg_phase_a_current_2
  1247.         device_address: !secret sungrow_modbus_slave_inv2
  1248.         address: 13030 # reg 13031
  1249.         input_type: input
  1250.         data_type: int16
  1251.         precision: 1
  1252.         unit_of_measurement: A
  1253.         device_class: current
  1254.         state_class: measurement
  1255.         scale: 0.1
  1256.         scan_interval: 10
  1257.  
  1258.       - name: Phase B current 2
  1259.         unique_id: sg_phase_b_current_2
  1260.         device_address: !secret sungrow_modbus_slave_inv2
  1261.         address: 13031 # reg 13032
  1262.         input_type: input
  1263.         data_type: int16
  1264.         precision: 1
  1265.         unit_of_measurement: A
  1266.         device_class: current
  1267.         state_class: measurement
  1268.         scale: 0.1
  1269.         scan_interval: 10
  1270.  
  1271.       - name: Phase C current 2
  1272.         unique_id: sg_phase_c_current_2
  1273.         device_address: !secret sungrow_modbus_slave_inv2
  1274.         address: 13032 # reg 13033
  1275.         input_type: input
  1276.         data_type: int16
  1277.         precision: 1
  1278.         unit_of_measurement: A
  1279.         device_class: current
  1280.         state_class: measurement
  1281.         scale: 0.1
  1282.         scan_interval: 10
  1283.  
  1284.       - name: Total active power 2
  1285.         unique_id: sg_total_active_power_2
  1286.         device_address: !secret sungrow_modbus_slave_inv2
  1287.         address: 13033 # reg 13034
  1288.         input_type: input
  1289.         data_type: int32
  1290.         swap: word
  1291.         precision: 0
  1292.         unit_of_measurement: W
  1293.         device_class: power
  1294.         state_class: measurement
  1295.         scale: 1
  1296.         scan_interval: 10
  1297.  
  1298.       - name: Daily imported energy 2
  1299.         unique_id: sg_daily_imported_energy_2
  1300.         device_address: !secret sungrow_modbus_slave_inv2
  1301.         address: 13035 # reg 13036
  1302.         input_type: input
  1303.         data_type: uint16
  1304.         precision: 1
  1305.         unit_of_measurement: kWh
  1306.         device_class: energy
  1307.         state_class: total_increasing
  1308.         scale: 0.1
  1309.         scan_interval: 600
  1310.  
  1311.       - name: Total imported energy 2
  1312.         unique_id: sg_total_imported_energy_2
  1313.         device_address: !secret sungrow_modbus_slave_inv2
  1314.         address: 13036 # reg 13037
  1315.         input_type: input
  1316.         data_type: uint32
  1317.         swap: word
  1318.         precision: 1
  1319.         unit_of_measurement: kWh
  1320.         device_class: energy
  1321.         state_class: total
  1322.         scale: 0.1
  1323.         scan_interval: 600
  1324.  
  1325.       - name: Daily battery charge 2
  1326.         unique_id: sg_daily_battery_charge_2
  1327.         device_address: !secret sungrow_modbus_slave_inv2
  1328.         address: 13039 # reg 13040
  1329.         input_type: input
  1330.         data_type: uint16
  1331.         precision: 1
  1332.         unit_of_measurement: kWh
  1333.         device_class: energy
  1334.         state_class: total_increasing
  1335.         scale: 0.1
  1336.         scan_interval: 600
  1337.  
  1338.       - name: Total battery charge 2
  1339.         unique_id: sg_total_battery_charge_2
  1340.         device_address: !secret sungrow_modbus_slave_inv2
  1341.         address: 13040 # reg 13041
  1342.         input_type: input
  1343.         data_type: uint32
  1344.         swap: word
  1345.         precision: 1
  1346.         unit_of_measurement: kWh
  1347.         device_class: energy
  1348.         state_class: total
  1349.         scale: 0.1
  1350.         scan_interval: 600
  1351.  
  1352.       - name: Daily exported energy 2
  1353.         unique_id: sg_daily_exported_energy_2
  1354.         device_address: !secret sungrow_modbus_slave_inv2
  1355.         address: 13044 # reg 13045
  1356.         input_type: input
  1357.         data_type: uint16
  1358.         precision: 1
  1359.         unit_of_measurement: kWh
  1360.         device_class: energy
  1361.         state_class: total_increasing
  1362.         scale: 0.1
  1363.         scan_interval: 600
  1364.  
  1365.       - name: Total exported energy 2
  1366.         unique_id: sg_total_exported_energy_2
  1367.         device_address: !secret sungrow_modbus_slave_inv2
  1368.         address: 13045 # reg 13046
  1369.         input_type: input
  1370.         data_type: uint32
  1371.         swap: word
  1372.         precision: 1
  1373.         unit_of_measurement: kWh
  1374.         device_class: energy
  1375.         state_class: total
  1376.         scale: 0.1
  1377.         scan_interval: 600
  1378.  
  1379.       #####################
  1380.       # holding registers
  1381.       #####################
  1382.       - name: Inverter start stop 2
  1383.         unique_id: sg_inverter_start_stop_2
  1384.         device_address: !secret sungrow_modbus_slave_inv2
  1385.         address: 12999 # reg 13000
  1386.         input_type: holding
  1387.         data_type: uint16
  1388.         precision: 0
  1389.         state_class: measurement
  1390.         scan_interval: 10
  1391.  
  1392.       - name: EMS mode selection raw 2
  1393.         unique_id: sg_ems_mode_selection_raw_2
  1394.         device_address: !secret sungrow_modbus_slave_inv2
  1395.         address: 13049 # reg 13050
  1396.         input_type: holding
  1397.         data_type: uint16
  1398.         state_class: measurement
  1399.         scan_interval: 10
  1400.  
  1401.       - name: Battery forced charge discharge cmd raw 2
  1402.         unique_id: sg_battery_forced_charge_discharge_cmd_raw_2
  1403.         device_address: !secret sungrow_modbus_slave_inv2
  1404.         address: 13050 # reg 13051
  1405.         input_type: holding
  1406.         data_type: uint16
  1407.         precision: 0
  1408.         state_class: measurement
  1409.         scan_interval: 10
  1410.  
  1411.       - name: Battery forced charge discharge power 2
  1412.         unique_id: sg_battery_forced_charge_discharge_power_2
  1413.         device_address: !secret sungrow_modbus_slave_inv2
  1414.         address: 13051 # reg 13052
  1415.         input_type: holding
  1416.         data_type: uint16
  1417.         precision: 0
  1418.         # datasheet says:
  1419.         # 0 to 5000 W for SH*K-*
  1420.         # 0 to 100 % for SH*.0RT
  1421.         # for my SH10RT it is set in Watt, not in %
  1422.         unit_of_measurement: W
  1423.         device_class: power
  1424.         state_class: measurement
  1425.         scan_interval: 10
  1426.  
  1427.       - name: Max SoC 2
  1428.         unique_id: sg_max_soc_2
  1429.         device_address: !secret sungrow_modbus_slave_inv2
  1430.         address: 13057 # reg 13058
  1431.         input_type: holding
  1432.         data_type: uint16
  1433.         precision: 1
  1434.         unit_of_measurement: "%"
  1435.         device_class: battery
  1436.         state_class: measurement
  1437.         scale: 0.1
  1438.         scan_interval: 10
  1439.  
  1440.       - name: Min SoC 2
  1441.         unique_id: sg_min_soc_2
  1442.         device_address: !secret sungrow_modbus_slave_inv2
  1443.         address: 13058 # reg 13059
  1444.         input_type: holding
  1445.         data_type: uint16
  1446.         precision: 1
  1447.         unit_of_measurement: "%"
  1448.         device_class: battery
  1449.         state_class: measurement
  1450.         scale: 0.1
  1451.         scan_interval: 10
  1452.  
  1453.       - name: Export power limit 2
  1454.         unique_id: sg_export_power_limit_2
  1455.         device_address: !secret sungrow_modbus_slave_inv2
  1456.         address: 13073 # reg 13074
  1457.         input_type: holding
  1458.         data_type: uint16
  1459.         precision: 0
  1460.         unit_of_measurement: "W"
  1461.         device_class: power
  1462.         state_class: measurement
  1463.         scale: 1
  1464.         scan_interval: 10
  1465.  
  1466.       - name: Export power limit mode raw 2
  1467.         unique_id: sg_export_power_limit_mode_raw_2
  1468.         device_address: !secret sungrow_modbus_slave_inv2
  1469.         address: 13086 # reg 13087
  1470.         input_type: holding
  1471.         data_type: uint16
  1472.         precision: 0
  1473.         state_class: measurement
  1474.         scan_interval: 10
  1475.  
  1476.       - name: Reserved SoC for backup 2
  1477.         unique_id: sg_reserved_soc_for_backup_2
  1478.         device_address: !secret sungrow_modbus_slave_inv2
  1479.         address: 13099 # reg 13100
  1480.         input_type: holding
  1481.         data_type: uint16
  1482.         unit_of_measurement: "%"
  1483.         device_class: battery
  1484.         state_class: measurement
  1485.         scale: 1
  1486.         scan_interval: 10
  1487.  
  1488.       #undocumented sensors (reverse engineered by some guys of photovoltaikforum.com and forum.iobroker.net )
  1489.       - name: Battery max charge power 2
  1490.         unique_id: sg_battery_max_charge_power_2
  1491.         device_address: !secret sungrow_modbus_slave_inv2
  1492.         address: 33046 # reg 33047
  1493.         input_type: holding
  1494.         data_type: uint16
  1495.         precision: 0
  1496.         unit_of_measurement: W
  1497.         device_class: power
  1498.         state_class: measurement
  1499.         scale: 10
  1500.         scan_interval: 10
  1501.  
  1502.       - name: Battery max discharge power 2
  1503.         unique_id: sg_battery_max_discharge_power_2
  1504.         device_address: !secret sungrow_modbus_slave_inv2
  1505.         address: 33047 # reg 33048
  1506.         input_type: holding
  1507.         data_type: uint16
  1508.         precision: 0
  1509.         unit_of_measurement: W
  1510.         device_class: power
  1511.         state_class: measurement
  1512.         scale: 10
  1513.         scan_interval: 10
  1514.  
  1515.       - name: Battery capacity 2
  1516.         unique_id: sg_battery_capacity_2
  1517.         device_address: !secret sungrow_modbus_slave_inv2
  1518.         address: 33048 # reg 33049
  1519.         input_type: holding
  1520.         data_type: uint16
  1521.         precision: 1
  1522.         unit_of_measurement: kWh
  1523.         device_class: energy_storage
  1524.         scale: 0.01
  1525.         scan_interval: 600
  1526.  
  1527.       - name: Battery charging start power 2
  1528.         unique_id: sg_battery_charging_start_power_2
  1529.         device_address: !secret sungrow_modbus_slave_inv2
  1530.         address: 33148 # reg 33149
  1531.         input_type: holding
  1532.         data_type: uint16
  1533.         precision: 0
  1534.         unit_of_measurement: W
  1535.         device_class: power
  1536.         state_class: measurement
  1537.         scale: 10
  1538.         scan_interval: 10
  1539.  
  1540.       - name: Battery discharging start power 2
  1541.         unique_id: sg_battery_discharging_start_power_2
  1542.         device_address: !secret sungrow_modbus_slave_inv2
  1543.         address: 33149 # reg 33150
  1544.         input_type: holding
  1545.         data_type: uint16
  1546.         precision: 0
  1547.         unit_of_measurement: W
  1548.         device_class: power
  1549.         state_class: measurement
  1550.         scale: 10
  1551.         scan_interval: 10
  1552.  
  1553.       - name: Global mpp scan manual raw 2
  1554.         unique_id: sg_global_mpp_scan_manual_raw_2
  1555.         device_address: !secret sungrow_modbus_slave_inv2
  1556.         address: 30229 # reg 30230
  1557.         input_type: holding
  1558.         data_type: uint16
  1559.         precision: 0
  1560.         state_class: measurement
  1561.         scan_interval: 10
  1562.  
  1563. # 'virtual' template sensors for better readability
  1564. template:
  1565.   - binary_sensor:
  1566.       - name: PV generating 2
  1567.         unique_id: sg_pv_generating_2
  1568.         # TODO: test more with these parameters for template binary sensors
  1569.         # device_class: none / power
  1570.         # state_class: measurement
  1571.         availability: >-
  1572.           {{
  1573.           not is_state('sensor.running_state_2', 'unavailable')
  1574.           and not is_state('sensor.total_dc_power_2', 'unavailable')
  1575.           }}
  1576.         state: >-
  1577.           {% if states('sensor.running_state_2')|is_number %}
  1578.             {# use available sensor.running_state_2 #}
  1579.             {{ states('sensor.running_state_2')|int |bitwise_and(0x1) }}
  1580.           {% else %}
  1581.             {# workaround for SH*RS inverters without working running_state #}
  1582.             {% if states('sensor.total_dc_power_2')|int > 0 %}
  1583.               1
  1584.             {% else %}
  1585.               0
  1586.             {% endif %}
  1587.           {% endif %}
  1588.  
  1589.       - name: PV generating (delay) 2
  1590.         unique_id: sg_pv_generating_delay_2
  1591.         # TODO: test more with these parameters for template binary sensors
  1592.         # device_class: none / power
  1593.         # state_class: measurement
  1594.         availability: "{{ not is_state('binary_sensor.pv_generating_2', 'unavailable') }}"
  1595.         delay_on:
  1596.           seconds: 60
  1597.         state: "{{ states('binary_sensor.pv_generating_2') }}"
  1598.  
  1599.       - name: Battery charging 2
  1600.         unique_id: sg_battery_charging_2
  1601.         # TODO: test more with these parameters for template binary sensors
  1602.         # device_class: none / power
  1603.         # state_class: measurement
  1604.         availability: >-
  1605.           {{
  1606.           not is_state('sensor.running_state_2', 'unavailable')
  1607.           or
  1608.             (   not is_state('sensor.ems_mode_selection_raw_2', 'unavailable')
  1609.             and not is_state('sensor.battery_forced_charge_discharge_cmd_raw_2', 'unavailable')
  1610.             and not is_state('sensor.battery_power_raw_2', 'unavailable')
  1611.             and not is_state('sensor.total_dc_power_2', 'unavailable')
  1612.             and not is_state('sensor.load_power_2', 'unavailable')
  1613.             )
  1614.           }}
  1615.         state: >-
  1616.           {% if states('sensor.running_state_2')|is_number %}
  1617.             {# use available sensor.running_state_2 #}
  1618.             {% if states('sensor.running_state_2')|int(default=0)|bitwise_and(0x2) > 0 %}
  1619.               on
  1620.             {% else %}
  1621.               off
  1622.             {% endif %}
  1623.           {% else %}
  1624.             {# workaround for SH*RS inverters without working running_state #}
  1625.             {% if (states('sensor.ems_mode_selection_2') ) == "Forced mode" %}
  1626.               {# EMS forced mode #}
  1627.               {% if (states('sensor.battery_forced_charge_discharge_cmd_2') == "Forced charge") %}
  1628.                 {# in mode Forced charge #}
  1629.                 {% if (states('sensor.battery_power_raw_2')|int > 0 ) %}
  1630.                   {# power flow from/to battery #}
  1631.                   on
  1632.                 {% else %}
  1633.                   {# no power flow from/to battery #}
  1634.                   off
  1635.                 {% endif %}
  1636.               {% else %}
  1637.                 {# in EMS mode, but not in mode Forced charge #}
  1638.                 off
  1639.               {% endif %}
  1640.             {% else %}
  1641.               {# not in EMS forced mode, assuming self consumption mode #}
  1642.               {% if states('sensor.total_dc_power_2')|int > states('sensor.load_power_2')|int %}
  1643.                 {# more power generated than consumed. assuming battery charging #}
  1644.                 on
  1645.               {% else %}
  1646.                 off
  1647.               {% endif %}
  1648.             {% endif %}
  1649.           {% endif %}
  1650.  
  1651.       - name: Battery charging (delay) 2
  1652.         unique_id: sg_battery_charging_delay_2
  1653.         # TODO: test more with these parameters for template binary sensors
  1654.         # device_class: none / power
  1655.         # state_class: measurement
  1656.         availability: "{{ not is_state('binary_sensor.battery_charging_2', 'unavailable') }}"
  1657.         delay_on:
  1658.           seconds: 60
  1659.         state: "{{ states('binary_sensor.battery_charging_2') }}"
  1660.  
  1661.       - name: Battery discharging 2
  1662.         unique_id: sg_battery_discharging_2
  1663.         # TODO: test more with these parameters for template binary sensors
  1664.         # device_class: none / power
  1665.         # state_class: measurement
  1666.         availability: >-
  1667.           {{
  1668.           not is_state('sensor.running_state_2', 'unavailable')
  1669.           or
  1670.             (   not is_state('sensor.ems_mode_selection_raw_2', 'unavailable')
  1671.             and not is_state('sensor.battery_forced_charge_discharge_cmd_raw_2', 'unavailable')
  1672.             and not is_state('sensor.battery_power_raw_2', 'unavailable')
  1673.             and not is_state('sensor.total_dc_power_2', 'unavailable')
  1674.             and not is_state('sensor.load_power_2', 'unavailable')
  1675.             )
  1676.           }}
  1677.         state: >-
  1678.           {% if states('sensor.running_state_2')|is_number %}
  1679.             {# use available sensor.running_state_2 #}
  1680.             {% if states('sensor.running_state_2')|int(default=0)|bitwise_and(0x4) > 0 %}
  1681.               on
  1682.             {% else %}
  1683.               off
  1684.             {% endif %}
  1685.           {% else %}
  1686.             {# workaround for SH*RS inverters without working running_state #}
  1687.             {% if (states('sensor.ems_mode_selection_2') ) == "Forced mode" %}
  1688.               {# EMS forced mode #}
  1689.               {% if (states('sensor.battery_forced_charge_discharge_cmd_2') == "Forced discharge") %}
  1690.                 {# in mode Forced discharge #}
  1691.                 {% if (states('sensor.battery_power_raw_2')|int > 0 ) %}
  1692.                   {# power flow from/to battery #}
  1693.                   on
  1694.                 {% else %}
  1695.                   {# no power flow from/to battery #}
  1696.                   off
  1697.                 {% endif %}
  1698.               {% else %}
  1699.                 {# in EMS mode, but not in mode Forced charge #}
  1700.                 off
  1701.               {% endif %}
  1702.             {% else %}
  1703.               {# not in EMS forced mode, assuming self consumption mode #}
  1704.               {% if ( ( states('sensor.total_dc_power_2')|int < states('sensor.load_power_2')|int ) ) and states('sensor.battery_power_raw_2')|int > 0 %}
  1705.                 {# more power consumed than generated and some battery power --> assuming battery discharging #}
  1706.                 on
  1707.               {% else %}
  1708.                 off
  1709.               {% endif %}
  1710.             {% endif %}
  1711.           {% endif %}
  1712.  
  1713.       - name: Battery discharging (delay) 2
  1714.         unique_id: sg_battery_discharging_delay_2
  1715.         # TODO: test more with these parameters for template binary sensors
  1716.         # device_class: none / power
  1717.         # state_class: measurement
  1718.         availability: "{{ not is_state('binary_sensor.battery_discharging_2', 'unavailable') }}"
  1719.         delay_on:
  1720.           seconds: 60
  1721.         state: "{{ states('binary_sensor.battery_discharging_2') }}"
  1722.  
  1723.       - name: Exporting power 2
  1724.         unique_id: sg_exporting_power_2
  1725.         # TODO: test more with these parameters for template binary sensors
  1726.         # device_class: none / power
  1727.         # state_class: measurement
  1728.         availability: >-
  1729.           {{
  1730.           not is_state('sensor.running_state_2', 'unavailable')
  1731.           and not is_state('sensor.export_power_raw_2', 'unavailable')
  1732.           }}
  1733.         state: >-
  1734.           {% if states('sensor.running_state_2')|is_number %}
  1735.             {# use available sensor.running_state_2 #}
  1736.             {{ states('sensor.running_state_2')|int(default=0)|bitwise_and(0x10) > 0 }}
  1737.           {% else %}
  1738.             {# workaround for SH*RS inverters without working running_state #}
  1739.             {% if states('sensor.export_power_raw_2')|int > 0 %}
  1740.               1
  1741.             {% else %}
  1742.               0
  1743.             {% endif %}
  1744.           {% endif %}
  1745.  
  1746.       - name: Exporting power (delay) 2
  1747.         unique_id: sg_exporting_power_delay_2
  1748.         # TODO: test more with these parameters for template binary sensors
  1749.         # device_class: none / power
  1750.         # state_class: measurement
  1751.         availability: "{{ not is_state('binary_sensor.exporting_power_2', 'unavailable') }}"
  1752.         delay_on:
  1753.           seconds: 60
  1754.         state: "{{ states('binary_sensor.exporting_power_2') }}"
  1755.  
  1756.       - name: Importing power 2
  1757.         unique_id: sg_importing_power_2
  1758.         # TODO: test more with these parameters for template binary sensors
  1759.         # device_class: none / power
  1760.         # state_class: measurement
  1761.         availability: >-
  1762.           {{
  1763.           not is_state('sensor.running_state_2', 'unavailable')
  1764.           and not is_state('sensor.running_state_2', 'unavailable')
  1765.           }}
  1766.         state: >-
  1767.           {% if states('sensor.running_state_2')|is_number %}
  1768.             {# use available sensor.running_state_2 #}
  1769.             {{ states('sensor.running_state_2')|int(default=0)|bitwise_and(0x20) > 0 }}
  1770.           {% else %}
  1771.             {# workaround for SH*RS inverters without working running_state #}
  1772.             {% if states('sensor.export_power_raw_2')|int < 0 %}
  1773.               1
  1774.             {% else %}
  1775.               0
  1776.             {% endif %}
  1777.           {% endif %}
  1778.  
  1779.       - name: Importing power (delay) 2
  1780.         unique_id: sg_importing_power_delay_2
  1781.         # TODO: test more with these parameters for template binary sensors
  1782.         # device_class: none / power
  1783.         # state_class: measurement
  1784.         availability: "{{ not is_state('binary_sensor.importing_power_2', 'unavailable') }}"
  1785.         delay_on:
  1786.           seconds: 60
  1787.         state: "{{ states('binary_sensor.importing_power_2') }}"
  1788.  
  1789.   - sensor:
  1790.       - name: MPPT1 power 2
  1791.         unique_id: sg_mppt1_power_2
  1792.         unit_of_measurement: W
  1793.         device_class: power
  1794.         state_class: measurement
  1795.         availability: >-
  1796.           {{
  1797.           not is_state('sensor.mppt1_voltage_2', 'unavailable')
  1798.           and not is_state('sensor.mppt1_current_2', 'unavailable')
  1799.           }}
  1800.         state: "{{ (states('sensor.mppt1_voltage_2') | float * states('sensor.mppt1_current_2') | float) |int }}"
  1801.  
  1802.       - name: MPPT2 power 2
  1803.         unique_id: sg_mppt2_power_2
  1804.         unit_of_measurement: W
  1805.         device_class: power
  1806.         state_class: measurement
  1807.         availability: >-
  1808.           {{
  1809.           not is_state('sensor.mppt2_voltage_2', 'unavailable')
  1810.           and not is_state('sensor.mppt2_current_2', 'unavailable' )
  1811.           }}
  1812.         state: "{{ (states('sensor.mppt2_voltage_2') | float * states('sensor.mppt2_current_2') | float) |int }}"
  1813.  
  1814.       - name: Phase A power 2
  1815.         unique_id: sg_phase_a_power_2
  1816.         unit_of_measurement: W
  1817.         device_class: power
  1818.         state_class: measurement
  1819.         availability: >-
  1820.           {{
  1821.           not is_state('sensor.phase_a_voltage_2', 'unavailable')
  1822.           and not is_state('sensor.phase_a_current', 'unavailable')
  1823.           }}
  1824.         state: "{{ (states('sensor.phase_a_voltage_2') | float * states('sensor.phase_a_current') | float) |int }}"
  1825.  
  1826.       - name: Phase B power 2
  1827.         unique_id: sg_phase_b_power_2
  1828.         unit_of_measurement: W
  1829.         device_class: power
  1830.         state_class: measurement
  1831.         availability: >-
  1832.           {{
  1833.           not is_state('sensor.phase_b_voltage_2', 'unavailable')
  1834.           and not is_state('sensor.phase_b_current', 'unavailable')
  1835.           }}
  1836.         state: "{{ (states('sensor.phase_b_voltage_2') | float * states('sensor.phase_b_current') | float) |int }}"
  1837.  
  1838.       - name: Phase C power 2
  1839.         unique_id: sg_phase_c_power_2
  1840.         unit_of_measurement: W
  1841.         device_class: power
  1842.         state_class: measurement
  1843.         availability: >-
  1844.           {{
  1845.           not is_state('sensor.phase_c_voltage_2', 'unavailable')
  1846.           and not is_state('sensor.phase_c_current', 'unavailable')
  1847.           }}
  1848.         state: "{{ (states('sensor.phase_c_voltage_2') | float * states('sensor.phase_c_current') | float) |int }}"
  1849.  
  1850.       # template sensor in case the meter is not available (grid is off) and returns 0x7FFFFF
  1851.       - name: Meter active power 2
  1852.         unique_id: sg_meter_active_power_2
  1853.         unit_of_measurement: W
  1854.         device_class: power
  1855.         state_class: measurement
  1856.         availability: >-
  1857.           {{
  1858.           not is_state('sensor.meter_active_power_raw_2', 'unavailable')
  1859.           and states('sensor.meter_active_power_raw_2')|int != 0x7FFFFFFF
  1860.           }}
  1861.         state: "{{ states('sensor.meter_active_power_raw_2') }}"
  1862.  
  1863.       # template sensor in case the meter is not available (grid is off) and returns 0x7FFFFF
  1864.       - name: Meter Phase A active power 2
  1865.         unique_id: sg_meter_phase_a_active_power_2
  1866.         unit_of_measurement: W
  1867.         device_class: power
  1868.         state_class: measurement
  1869.         availability: >-
  1870.           {{
  1871.           not is_state('sensor.meter_phase_a_active_power_raw_2', 'unavailable')
  1872.           and states('sensor.meter_phase_a_active_power_raw_2')|int != 0x7FFFFFFF
  1873.           }}
  1874.         state: "{{ states('sensor.meter_phase_a_active_power_raw_2') }}"
  1875.  
  1876.       # template sensor in case the meter is not available (grid is off) and returns 0x7FFFFF
  1877.       - name: Meter Phase B active power 2
  1878.         unique_id: sg_meter_phase_b_active_power_2
  1879.         unit_of_measurement: W
  1880.         device_class: power
  1881.         state_class: measurement
  1882.         availability: >-
  1883.           {{
  1884.           not is_state('sensor.meter_phase_b_active_power_raw_2', 'unavailable')
  1885.           and states('sensor.meter_phase_b_active_power_raw_2')|int != 0x7FFFFFFF
  1886.           }}
  1887.         state: "{{ states('sensor.meter_phase_b_active_power_raw_2') }}"
  1888.  
  1889.       # template sensor in case the meter is not available (grid is off) and returns 0x7FFFFF
  1890.       - name: Meter Phase C active power 2
  1891.         unique_id: sg_meter_phase_c_active_power_2
  1892.         unit_of_measurement: W
  1893.         device_class: power
  1894.         state_class: measurement
  1895.         availability: >-
  1896.           {{
  1897.           not is_state('sensor.meter_phase_c_active_power_raw_2', 'unavailable')
  1898.           and states('sensor.meter_phase_c_active_power_raw_2')|int != 0x7FFFFFFF
  1899.           }}
  1900.         state: "{{ states('sensor.meter_phase_c_active_power_raw_2') }}"
  1901.  
  1902.       - name: Sungrow inverter state 2
  1903.         unique_id: sg_inverter_state_2
  1904.         # TODO: test state_class with enum
  1905.         # state_class: measurement
  1906.         device_class: enum
  1907.         availability: "{{ not is_state('sensor.system_state_2', 'unavailable') }}"
  1908.         state: >-
  1909.           {% if ((states('sensor.system_state_2') | int(default=0)) == 0x0002) %}
  1910.             Stop
  1911.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x0008) %}
  1912.             Standby
  1913.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x0010) %}
  1914.             Initial Standby
  1915.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x0020) %}
  1916.             Startup
  1917.           {% elif ((states('sensor.system_state_2') | int(default=0)) in [0x0000,0x0040]) %}
  1918.             Running
  1919.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x0100) %}
  1920.             Fault
  1921.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x0400) %}
  1922.             Maintain mode
  1923.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x0800) %}
  1924.             Forced mode
  1925.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x1000) %}
  1926.             Off-grid mode
  1927.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x2501) %}
  1928.             Restarting
  1929.           {% elif ((states('sensor.system_state_2') | int(default=0)) == 0x4000) %}
  1930.             External EMS mode
  1931.           {% else %}
  1932.             Unknown - should not see me!
  1933.           {% endif %}
  1934.  
  1935.       - name: Sungrow device type 2
  1936.         unique_id: sg_device_type_2
  1937.         availability: "{{ not is_state('sensor.sungrow_device_type_code_2', 'unavailable') }}"
  1938.         # TODO: test state_class with enum
  1939.         # state_class: measurement
  1940.         device_class: enum
  1941.         state: >-
  1942.           {% if ((states('sensor.sungrow_device_type_code_2') | int(default=0))  == 0x0D06) %}
  1943.             SH3K6
  1944.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D07) %}
  1945.             SH4K6
  1946.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D09) %}
  1947.             SH5K-20  
  1948.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D03) %}
  1949.             SH5K-V13
  1950.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D0A) %}
  1951.             SH3K6-30
  1952.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D0B) %}
  1953.             SH4K6-30
  1954.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D0C) %}
  1955.             SH5K-30
  1956.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D17) %}
  1957.             SH3.RS
  1958.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D0D) %}
  1959.             SH3.6RS
  1960.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D18) %}
  1961.             SH4.0RS
  1962.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D0F) %}
  1963.             SH5.0RS
  1964.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D10) %}
  1965.             SH6.0RS
  1966.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D1A) %}
  1967.             SH8.0RS
  1968.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D1B) %}
  1969.             SH10RS
  1970.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E00) %}
  1971.             SH5.0RT
  1972.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E01) %}
  1973.             SH6.0RT
  1974.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E02) %}
  1975.             SH8.0RT
  1976.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E03) %}
  1977.             SH10RT
  1978.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E10) %}
  1979.             SH5.0RT-20
  1980.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E11) %}
  1981.             SH6.0RT-20
  1982.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E12) %}
  1983.             SH8.0RT-20
  1984.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E13) %}
  1985.             SH10RT-20
  1986.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E0C) %}
  1987.             SH5.0RT-V112
  1988.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E0D) %}
  1989.             SH6.0RT-V112
  1990.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E0E) %}
  1991.             SH8.0RT-V112
  1992.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E0F) %}
  1993.             SH10RT-V112
  1994.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E08) %}
  1995.             SH5.0RT-V122
  1996.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E09) %}
  1997.             SH6.0RT-V122
  1998.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E0A) %}
  1999.             SH8.0RT-V122
  2000.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E0B) %}
  2001.             SH10RT-V122
  2002.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E20) %}
  2003.             SH5T-V11
  2004.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E21) %}
  2005.             SH6T-V11
  2006.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E22) %}
  2007.             SH8T-V11
  2008.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E23) %}
  2009.             SH10T-V11
  2010.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E24) %}
  2011.             SH12T-V11
  2012.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E25) %}
  2013.             SH15T-V11
  2014.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E26) %}
  2015.             SH20T-V11
  2016.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E28) %}
  2017.             SH25T-V11
  2018.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0D0E) %}
  2019.             SH4.6RS
  2020.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E26) %}
  2021.             SH20T
  2022.           {% elif ((states('sensor.sungrow_device_type_code_2') | int(default=0)) == 0x0E28) %}
  2023.             SH25T
  2024.           {% else %}
  2025.             Unknown device code: {{ '%0x' % (states('sensor.sungrow_device_type_code_2') | int(default=0))  }}
  2026.           {% endif %}
  2027.  
  2028.       # make the sensor.battery_forced_charge_discharge_cmd_2 more human readable
  2029.       # Inverter States from modbus reference manual
  2030.       # 0xAA forced charge
  2031.       # 0xBB forced discharge
  2032.       # 0xCC Stop (default)
  2033.       - name: Battery forced charge discharge cmd 2
  2034.         unique_id: sg_battery_forced_charge_discharge_cmd_2
  2035.         availability: "{{ not is_state('sensor.battery_forced_charge_discharge_cmd_raw_2', 'unavailable') }}"
  2036.         # TODO: test state_class with enum
  2037.         # state_class: measurement
  2038.         device_class: enum
  2039.         state: >-
  2040.           {% if ((states('sensor.battery_forced_charge_discharge_cmd_raw_2') | int(default=0)) == 0x00AA) %}
  2041.             Forced charge
  2042.           {% elif ((states('sensor.battery_forced_charge_discharge_cmd_raw_2') | int(default=0))  == 0x00BB) %}
  2043.             Forced discharge
  2044.           {% elif ((states('sensor.battery_forced_charge_discharge_cmd_raw_2') | int(default=0))  == 0x00CC) %}
  2045.             Stop (default)
  2046.           {% else %}
  2047.             Unknown - should not see me!
  2048.           {% endif %}
  2049.  
  2050.       - name: Export power limit mode 2
  2051.         unique_id: export_power_limit_mode_2
  2052.         availability: "{{ not is_state('sensor.export_power_limit_mode_raw_2', 'unavailable') }}"
  2053.         # TODO: test state_class with enum
  2054.         # state_class: measurement
  2055.         device_class: enum
  2056.         state: >-
  2057.           {% if ((states('sensor.export_power_limit_mode_raw_2') | int(default=0)) == 0x00AA) %}
  2058.             Enabled
  2059.           {% elif ((states('sensor.export_power_limit_mode_raw_2') | int(default=0))  == 0x0055) %}
  2060.             Disabled
  2061.           {% else %}
  2062.             Unknown - should not see me!
  2063.           {% endif %}
  2064.  
  2065.       # make the sensor ems_selection_raw more human readable
  2066.       - name: EMS mode selection 2
  2067.         unique_id: sg_ems_mode_selection_2
  2068.         availability: "{{ not is_state('sensor.ems_mode_selection_raw_2', 'unavailable') }}"
  2069.         # TODO: test state_class with enum with enum
  2070.         # state_class: measurement
  2071.         device_class: enum
  2072.         state: >-
  2073.           {% if ((states('sensor.ems_mode_selection_raw_2') | int(default=0)) == 0) %}
  2074.             Self-consumption mode (default)
  2075.           {% elif ((states('sensor.ems_mode_selection_raw_2') | int(default=0)) == 2) %}
  2076.             Forced mode
  2077.           {% elif ((states('sensor.ems_mode_selection_raw_2') | int(default=0)) == 3) %}
  2078.             External EMS
  2079.           {% elif ((states('sensor.ems_mode_selection_raw_2') | int(default=0)) == 4) %}
  2080.             VPP
  2081.           {% elif ((states('sensor.ems_mode_selection_raw_2') | int(default=0)) == 8) %}
  2082.             MicroGrid
  2083.           {% else %}
  2084.             Unknown - should not see me!
  2085.           {% endif %}
  2086.  
  2087.       - name: Signed battery power  2 # positive if charging and negative if discharging
  2088.         unique_id: sg_signed_battery_power_2
  2089.         unit_of_measurement: W
  2090.         device_class: power
  2091.         state_class: measurement
  2092.         availability: >-
  2093.           {{
  2094.           not is_state('binary_sensor.battery_charging_2', 'unavailable')
  2095.           and not is_state('binary_sensor.battery_discharging_2', 'unavailable')
  2096.           and not is_state('sensor.battery_power_raw_2', 'unavailable')
  2097.           }}
  2098.         state: >-
  2099.           {% if is_state('binary_sensor.battery_charging_2', 'on') %}
  2100.             {{ (states('sensor.battery_power_raw_2') | float)}}
  2101.           {% elif is_state('binary_sensor.battery_discharging_2', 'on') %}
  2102.             {{ (states('sensor.battery_power_raw_2') | float * -1)}}
  2103.           {% else %}
  2104.             0
  2105.           {% endif %}
  2106.  
  2107.       - name: Battery charging power  2 # positive if charging else zero
  2108.         unique_id: sg_battery_charging_power_2
  2109.         unit_of_measurement: W
  2110.         device_class: power
  2111.         state_class: measurement
  2112.         availability: >-
  2113.           {{
  2114.           not is_state('binary_sensor.battery_charging_2', 'unavailable')
  2115.           and not is_state('sensor.battery_power_raw_2', 'unavailable')
  2116.           }}
  2117.         state: >-
  2118.           {% if is_state('binary_sensor.battery_charging_2', 'on') %}
  2119.             {{ states('sensor.battery_power_raw_2') }}
  2120.           {% else %}
  2121.             0
  2122.           {% endif %}
  2123.  
  2124.       - name: Battery discharging power  2 # positive if discharging else zero
  2125.         unique_id: sg_battery_discharging_power_2
  2126.         unit_of_measurement: W
  2127.         device_class: power
  2128.         state_class: measurement
  2129.         availability: >-
  2130.           {{
  2131.           not is_state('binary_sensor.battery_discharging_2', 'unavailable')
  2132.           and not is_state('sensor.battery_power_raw_2', 'unavailable')
  2133.           }}
  2134.         state: >-
  2135.           {% if is_state('binary_sensor.battery_discharging_2', 'on') %}
  2136.             {{ states('sensor.battery_power_raw_2') }}
  2137.           {% else %}
  2138.             0
  2139.           {% endif %}
  2140.  
  2141.       - name: Import power  2 # power from grid: positive if importing, else zero
  2142.         unique_id: sg_import_power_2
  2143.         unit_of_measurement: W
  2144.         device_class: power
  2145.         state_class: measurement
  2146.         availability: "{{ not is_state('sensor.export_power_raw_2', 'unavailable') }}"
  2147.         state: >-
  2148.           {% if states('sensor.export_power_raw_2')|int < 0 %}
  2149.             {{ states('sensor.export_power_raw_2')|int *-1 }}
  2150.           {% else %}
  2151.             0
  2152.           {% endif %}
  2153.  
  2154.       - name: Export power  2 # power to grid: positive if exporting, else zero
  2155.         unique_id: sg_export_power_2
  2156.         unit_of_measurement: W
  2157.         device_class: power
  2158.         state_class: measurement
  2159.         availability: "{{states('sensor.export_power_raw_2')|is_number }}"
  2160.         state: >-
  2161.           {% if states('sensor.export_power_raw_2')|int > 0 %}
  2162.             {{ states('sensor.export_power_raw_2') }}
  2163.           {% else %}
  2164.             0
  2165.           {% endif %}
  2166.  
  2167.       - name: "Monthly PV generation (current) 2"
  2168.         unique_id: sg_monthly_pv_generation_current_2
  2169.         unit_of_measurement: kWh
  2170.         device_class: energy
  2171.         state_class: total_increasing
  2172.         availability: >-
  2173.           {% set currMonth = 'monthly_pv_generation_' ~ '%0.2d' % now().month ~ '_' ~ now().timestamp() | timestamp_custom('%B') | lower %}
  2174.           {{ states('sensor.' ~ currMonth)|is_number }}
  2175.         state: >
  2176.          {% set currMonth = 'monthly_pv_generation_' ~ '%0.2d' % now().month ~ '_' ~ now().timestamp() | timestamp_custom('%B') | lower %}
  2177.           {{ states('sensor.' ~ currMonth) }}
  2178.  
  2179.       - name: "Yearly PV generation (current) 2"
  2180.         unique_id: sg_yearly_pv_generation_current_2
  2181.         unit_of_measurement: kWh
  2182.         device_class: energy
  2183.         state_class: total_increasing
  2184.         availability: >-
  2185.           {% set currYear = 'yearly_pv_generation_' ~ now().year %}
  2186.           {{ states('sensor.' ~ currYear)|is_number }}
  2187.         state: >
  2188.          {% set currYear = 'yearly_pv_generation_' ~ now().year %}
  2189.           {{ states('sensor.' ~ currYear) }}
  2190.  
  2191.       - name: "Monthly export (current) 2"
  2192.         unique_id: sg_monthly_export_current_2
  2193.         unit_of_measurement: kWh
  2194.         device_class: energy
  2195.         state_class: total_increasing
  2196.         availability: >-
  2197.           {% set currMonth = 'monthly_export_' ~ '%0.2d' % now().month ~ '_' ~ now().timestamp() | timestamp_custom('%B') | lower %}
  2198.           {{ states('sensor.' ~ currMonth)|is_number }}
  2199.         state: >
  2200.          {% set currMonth = 'monthly_export_' ~ '%0.2d' % now().month ~ '_' ~ now().timestamp() | timestamp_custom('%B') | lower %}
  2201.           {{ states('sensor.' ~ currMonth) }}
  2202.  
  2203.       - name: "Yearly export (current) 2"
  2204.         unique_id: sg_yearly_export_current_2
  2205.         unit_of_measurement: kWh
  2206.         device_class: energy
  2207.         state_class: total_increasing
  2208.         availability: >-
  2209.           {% set currYear = 'yearly_export_' ~ now().year %}
  2210.           {{ states('sensor.' ~ currYear)|is_number }}
  2211.         state: >
  2212.          {% set currYear = 'yearly_export_' ~ now().year %}
  2213.           {{ states('sensor.' ~ currYear) }}
  2214.  
  2215.       - name: "Battery level (nominal) 2"
  2216.         unique_id: sg_battery_level_nom_2
  2217.         unit_of_measurement: "%"
  2218.         device_class: battery
  2219.         state_class: measurement
  2220.         availability: >-
  2221.           {{
  2222.           not is_state('sensor.battery_level_2', 'unavailable')
  2223.           and not is_state('sensor.min_soc_2', 'unavailable')
  2224.           and not is_state('sensor.max_soc_2', 'unavailable')
  2225.           }}
  2226.         state: >-
  2227.           {% set soc_min = states('sensor.min_soc_2') | float %}
  2228.           {% set soc_max = states('sensor.max_soc_2') | float %}
  2229.           {% set soc_cur = states('sensor.battery_level_2') | float %}
  2230.           {{
  2231.             ((soc_min) + ((soc_max - soc_min) * (soc_cur / 100))) | round(1)
  2232.           }}
  2233.  
  2234.       - name: "Battery charge (nominal) 2"
  2235.         unique_id: sg_battery_charge_nom_2
  2236.         unit_of_measurement: kWh
  2237.         device_class: energy_storage
  2238.         state_class: measurement
  2239.         availability: >-
  2240.           {{
  2241.           not is_state('sensor.battery_capacity_2', 'unavailable')
  2242.           and not is_state('sensor.battery_level_nominal_2', 'unavailable')
  2243.           }}
  2244.         state: >-
  2245.           {{
  2246.             ( states('sensor.battery_capacity_2') | float *
  2247.             states('sensor.battery_level_nominal_2') | float / 100 )| round(1)
  2248.           }}
  2249.  
  2250.       - name: "Battery charge 2"
  2251.         unique_id: sg_battery_charge_2
  2252.         unit_of_measurement: kWh
  2253.         device_class: energy_storage
  2254.         state_class: measurement
  2255.         availability: >-
  2256.           {{
  2257.           not is_state('sensor.battery_capacity_2', 'unavailable')
  2258.           and not is_state('sensor.battery_level_2', 'unavailable')
  2259.           and not is_state('sensor.min_soc_2', 'unavailable')
  2260.           and not is_state('sensor.max_soc_2', 'unavailable')
  2261.           }}
  2262.         state: >-
  2263.           {{
  2264.             ( states('sensor.battery_capacity_2')|float
  2265.             * ( states('sensor.max_soc_2')|float - states('sensor.min_soc_2')|float ) /100
  2266.             * states('sensor.battery_level_2')|float /100
  2267.             ) |round(2)
  2268.           }}
  2269.  
  2270.       - name: Daily consumed energy 2
  2271.         unique_id: uid_daily_consumed_energy_2
  2272.         unit_of_measurement: kWh
  2273.         device_class: energy
  2274.         state_class: total_increasing
  2275.         availability: >-
  2276.           {{
  2277.           not is_state('sensor.daily_pv_generation_2', 'unavailable')
  2278.           and not is_state('sensor.daily_exported_energy_2', 'unavailable')
  2279.           and not is_state('sensor.daily_imported_energy_2', 'unavailable')
  2280.           and not is_state('sensor.daily_battery_charge_2', 'unavailable')
  2281.           and not is_state('sensor.daily_battery_discharge_2', 'unavailable')
  2282.           }}
  2283.         state: >-
  2284.           {{
  2285.             (
  2286.               states('sensor.daily_pv_generation_2')|float
  2287.               - states('sensor.daily_exported_energy_2')|float
  2288.               + states('sensor.daily_imported_energy_2')|float
  2289.               - states('sensor.daily_battery_charge_2')|float
  2290.               + states('sensor.daily_battery_discharge_2')|float
  2291.             )|int
  2292.           }}
  2293.  
  2294.       - name: Total consumed energy 2
  2295.         unique_id: uid_total_consumed_energy_2
  2296.         unit_of_measurement: kWh
  2297.         device_class: energy
  2298.         state_class: total
  2299.         availability: >-
  2300.           {{
  2301.           not is_state('sensor.total_pv_generation_2', 'unavailable')
  2302.           and not is_state('sensor.total_exported_energy_2', 'unavailable')
  2303.           and not is_state('sensor.total_imported_energy_2', 'unavailable')
  2304.           and not is_state('sensor.total_battery_charge_2', 'unavailable')
  2305.           and not is_state('sensor.total_battery_discharge_2', 'unavailable')
  2306.           }}
  2307.         state: >-
  2308.           {{
  2309.             (
  2310.               states('sensor.total_pv_generation_2')|float
  2311.               - states('sensor.total_exported_energy_2')|float
  2312.               + states('sensor.total_imported_energy_2')|float
  2313.               - states('sensor.total_battery_charge_2')|float
  2314.               + states('sensor.total_battery_discharge_2')|float
  2315.             )|int
  2316.           }}
  2317.  
  2318. # getting input for Min and Max SoC
  2319. input_number:
  2320.   set_sg_2_min_soc:
  2321.     name: Set min SoC
  2322.     min: 0
  2323.     max: 50
  2324.     step: 1
  2325.  
  2326.   set_sg_2_max_soc:
  2327.     name: Set max SoC
  2328.     min: 50
  2329.     max: 100
  2330.     step: 1
  2331.  
  2332.   set_sg_2_reserved_soc_for_backup:
  2333.     name: Set reserved SoC for backup
  2334.     min: 0
  2335.     max: 100
  2336.     step: 1
  2337.  
  2338.   set_sg_2_forced_charge_discharge_power:
  2339.     name: Set forced charge discharge power in W
  2340.     min: 0
  2341.     max: 5000 # change this value according to the capability of your battery
  2342.     step: 100
  2343.  
  2344.   set_sg_2_battery_max_charge_power:
  2345.     name: Set max battery charge power in W
  2346.     min: 100
  2347.     max: 5000 # change this value according to the capability of your battery
  2348.     step: 100
  2349.  
  2350.   set_sg_2_battery_max_discharge_power:
  2351.     name: Set max battery discharge power in W
  2352.     min: 100
  2353.     max: 5000 # change this value according to the capability of your battery
  2354.     step: 100
  2355.  
  2356.   # This threshold is compared against the currently achievable charging power, not just against the currently available surplus.
  2357.   # If this is set higher than the maximum charging power of the battery, charging will not start.
  2358.   # If currently achievable charging power drops below this threshold, charging will stop. Actual charging power (limited by register 33047) is ignored.
  2359.   # Charging might stop before reaching 100% if set too close to the maximum charging power of the battery, due to achievable charging power naturally dropping at high state of charge.
  2360.   set_sg_2_battery_charging_start_power:
  2361.     name: Set battery charging start power in W
  2362.     min: 0
  2363.     max: 1000
  2364.     step: 10
  2365.  
  2366.   set_sg_2_battery_discharging_start_power:
  2367.     name: Set battery discharging start power in W
  2368.     min: 0
  2369.     max: 1000
  2370.     step: 10
  2371.  
  2372.   set_sg_2_export_power_limit:
  2373.     name: Set export power limit
  2374.     min: 0
  2375.     max: 10500 # Note: max for SH10.RT. It would be ncie to have this as a global variable /secret
  2376.     step: 100
  2377.  
  2378. input_select:
  2379.   set_sg_2_inverter_run_mode:
  2380.     name: Inverter mode
  2381.     options:
  2382.      - "Enabled"
  2383.       - "Shutdown"
  2384.  
  2385.   # get input for battery mode (forced charge/discharge, stop (default) )
  2386.   set_sg_2_ems_mode:
  2387.     name: EMS mode
  2388.     options:
  2389.      - "Self-consumption mode (default)"
  2390.       - "Forced mode"
  2391.       - "External EMS" # required for multiple inverters main /follower?
  2392.     # these are commented, because they are rarely used
  2393.     #      - "VPP"
  2394.     #      - "MicroGrid"
  2395.     icon: mdi:battery-unknown
  2396.  
  2397.   set_sg_2_battery_forced_charge_discharge_cmd:
  2398.     name: Battery forced charge discharge cmd
  2399.     options:
  2400.      - "Stop (default)"
  2401.       - "Forced charge"
  2402.       - "Forced discharge"
  2403.     icon: mdi:battery-unknown
  2404.  
  2405.   set_sg_2_export_power_limit_mode:
  2406.     name: Export power limit mode
  2407.     options:
  2408.      - "Enabled"
  2409.       - "Disabled"
  2410.     icon: mdi:export
  2411.  
  2412.   set_sg_2_global_mpp_scan_manual:
  2413.     name: Global mpp scan manual
  2414.     options:
  2415.      - "Enabled"
  2416.       - "Disabled"
  2417.     icon: mdi:export
  2418.  
  2419. # Automations: Write modbus registers on input changes via GUI
  2420. # note: If you change a value by the sliders, it will take up to 60 seconds until the state variables are updated
  2421. # Unfortunately, I could not find a way to "force update" modbus registers, yet...
  2422. automation:
  2423.   - id: "automation_sungrow_inverter_2_state"
  2424.     alias: "sungrow inverter 2 state"
  2425.     description: "Enables/ stops the inverter"
  2426.     trigger:
  2427.       - platform: state
  2428.         entity_id:
  2429.          - input_select.set_sg_2_inverter_run_mode
  2430.     condition: []
  2431.     variables:
  2432.       sg_start: 0xCF
  2433.       sg_stop: 0xCE
  2434.     action:
  2435.       - service: modbus.write_register
  2436.         data_template:
  2437.           hub: SungrowSHx
  2438.           slave: !secret sungrow_modbus_slave_inv2
  2439.           address: 12999 # reg 13000
  2440.           value: >
  2441.            {% if is_state('input_select.set_sg_2_inverter_run_mode', "Enabled") %}
  2442.               {{sg_start}}
  2443.             {% else %}
  2444.               {{sg_stop}}
  2445.             {% endif %}
  2446.     mode: single
  2447.  
  2448.   - id: "automation_sungrow_inverter_2_state_input_selector_update"
  2449.     alias: "sungrow inverter 2 enable/ stop input selector update"
  2450.     description: "Updates enable/ stops input selector"
  2451.     trigger:
  2452.       - platform: state
  2453.         entity_id:
  2454.          - sensor.sungrow_inverter_state_2
  2455.     condition:
  2456.       - condition: template
  2457.         value_template: "{{ not is_state('sensor.sungrow_inverter_state_2', 'unavailable') }}"
  2458.     action:
  2459.       - service: input_select.select_option
  2460.         target:
  2461.           entity_id: input_select.set_sg_2_inverter_run_mode
  2462.         data:
  2463.           option: >
  2464.            {% if is_state('sensor.sungrow_inverter_state_2', "Stop") %}
  2465.               Shutdown
  2466.             {% else %}
  2467.               Enabled
  2468.             {% endif %}
  2469.     mode: single
  2470.  
  2471.   - id: "automation_sungrow_inverter_2_update_max_soc"
  2472.     alias: "sungrow inverter 2 update max SoC"
  2473.     description: "Updates Sungrow max Soc holding register"
  2474.     trigger:
  2475.       - platform: state
  2476.         entity_id:
  2477.          - input_number.set_sg_2_max_soc
  2478.     condition: []
  2479.     action:
  2480.       - service: modbus.write_register
  2481.         data_template:
  2482.           hub: SungrowSHx
  2483.           slave: !secret sungrow_modbus_slave_inv2
  2484.           address: 13057 # reg 13058
  2485.           value: "{{ states('input_number.set_sg_2_max_soc') | int *10}}"
  2486.     mode: single
  2487.  
  2488.   - id: "automation_sungrow_inverter_2_update_max_soc_input_slider_update"
  2489.     alias: "sungrow inverter 2 max SoC input slider update"
  2490.     description: "Updates Sungrow max Soc input slider"
  2491.     trigger:
  2492.       - platform: state
  2493.         entity_id:
  2494.          - sensor.max_soc_2
  2495.     condition: []
  2496.     action:
  2497.       - service: input_number.set_value
  2498.         target:
  2499.           entity_id: input_number.set_sg_2_max_soc
  2500.         data:
  2501.           value: "{{ states('sensor.max_soc_2') }}"
  2502.     mode: single
  2503.  
  2504.   - id: "automation_sungrow_inverter_2_update_min_soc"
  2505.     alias: "sungrow inverter 2 update min SoC"
  2506.     description: "Updates Sungrow min Soc holding register"
  2507.     trigger:
  2508.       - platform: state
  2509.         entity_id:
  2510.          - input_number.set_sg_2_min_soc
  2511.     condition: []
  2512.     action:
  2513.       - service: modbus.write_register
  2514.         data_template:
  2515.           hub: SungrowSHx
  2516.           slave: !secret sungrow_modbus_slave_inv2
  2517.           address: 13058 # reg 13059
  2518.           value: "{{ states('input_number.set_sg_2_min_soc') | int *10}}"
  2519.     mode: single
  2520.  
  2521.   - id: "automation_sungrow_inverter_2_update_min_soc_input_slider_update"
  2522.     alias: "sungrow inverter 2 min SoC input slider update"
  2523.     description: "Updates Sungrow min Soc input slider"
  2524.     trigger:
  2525.       - platform: state
  2526.         entity_id:
  2527.          - sensor.min_soc_2
  2528.     condition: []
  2529.     action:
  2530.       - service: input_number.set_value
  2531.         target:
  2532.           entity_id: input_number.set_sg_2_min_soc
  2533.         data:
  2534.           value: "{{ states('sensor.min_soc_2') }}"
  2535.     mode: single
  2536.  
  2537.   - id: "automation_sungrow_inverter_2_update_reserved_soc_for_backup"
  2538.     alias: "sungrow inverter 2 update reserved soc for backup"
  2539.     description: "Updates reserved SoC for backup register"
  2540.     trigger:
  2541.       - platform: state
  2542.         entity_id:
  2543.          - input_number.set_sg_2_reserved_soc_for_backup
  2544.     condition: []
  2545.     action:
  2546.       - service: modbus.write_register
  2547.         data_template:
  2548.           hub: SungrowSHx
  2549.           slave: !secret sungrow_modbus_slave_inv2
  2550.           address: 13099 # reg 13100
  2551.           value: "{{ states('input_number.set_sg_2_reserved_soc_for_backup') | int}}"
  2552.     mode: single
  2553.  
  2554.   - id: "automation_sungrow_inverter_2_update_reserved_backup_soc_input_slider_update"
  2555.     alias: "sungrow inverter 2 reserved backup SoC input slider update"
  2556.     description: "Updates Sungrow reserved backup Soc input slider"
  2557.     trigger:
  2558.       - platform: state
  2559.         entity_id:
  2560.          - sensor.reserved_soc_for_backup_2
  2561.     condition: []
  2562.     action:
  2563.       - service: input_number.set_value
  2564.         target:
  2565.           entity_id: input_number.set_sg_2_reserved_soc_for_backup
  2566.         data:
  2567.           value: "{{ states('sensor.reserved_soc_for_backup_2') }}"
  2568.     mode: single
  2569.  
  2570.   - id: "automation_sungrow_inverter_2_update_battery_forced_charge_discharge_cmd"
  2571.     alias: "sungrow inverter 2 update battery forced charge discharge cmd"
  2572.     description: "Updates Sungrow holding register for battery forced charge discharge command"
  2573.     trigger:
  2574.       - platform: state
  2575.         entity_id:
  2576.          - input_select.set_sg_2_battery_forced_charge_discharge_cmd
  2577.     condition: []
  2578.     variables:
  2579.       ems_forced_charge: 0xAA
  2580.       ems_forced_discharge: 0xBB
  2581.       ems_stop_default: 0xCC
  2582.     action:
  2583.       - service: modbus.write_register
  2584.         data_template:
  2585.           hub: SungrowSHx
  2586.           slave: !secret sungrow_modbus_slave_inv2
  2587.           address: 13050 # reg 13051
  2588.           value: >
  2589.            {% if is_state('input_select.set_sg_2_battery_forced_charge_discharge_cmd', "Stop (default)") %}
  2590.               {{ems_stop_default}}
  2591.             {% elif is_state('input_select.set_sg_2_battery_forced_charge_discharge_cmd', "Forced charge") %}
  2592.               {{ems_forced_charge}}
  2593.             {% elif is_state('input_select.set_sg_2_battery_forced_charge_discharge_cmd', "Forced discharge") %}
  2594.               {{ems_forced_discharge}}
  2595.             {% else %}
  2596.               {{ems_stop_default}}
  2597.             {% endif %}
  2598.     mode: single
  2599.  
  2600.   - id: "automation_sungrow_inverter_2_update_battery_forced_charge_discharge_cmd_input_select_update"
  2601.     alias: "sungrow inverter 2 update battery forced charge discharge cmd input select update"
  2602.     description: "Updates Sungrow battery forced charge discharge cmd input select"
  2603.     trigger:
  2604.       - platform: state
  2605.         entity_id:
  2606.          - sensor.battery_forced_charge_discharge_cmd_2
  2607.     condition:
  2608.       - condition: template
  2609.         value_template: "{{ not is_state('sensor.battery_forced_charge_discharge_cmd_2', 'unavailable') }}"
  2610.     action:
  2611.       - service: input_select.select_option
  2612.         target:
  2613.           entity_id: input_select.set_sg_2_battery_forced_charge_discharge_cmd
  2614.         data:
  2615.           option: "{{ states('sensor.battery_forced_charge_discharge_cmd_2') }}"
  2616.     mode: single
  2617.  
  2618.   - id: "automation_sungrow_inverter_2_update_ems_mode"
  2619.     alias: "sungrow inverter 2 update EMS mode"
  2620.     description: "Updates EMS mode"
  2621.     trigger:
  2622.       - platform: state
  2623.         entity_id:
  2624.          - input_select.set_sg_2_ems_mode
  2625.     condition: []
  2626.     variables:
  2627.       ems_mode_self_consume: 0
  2628.       ems_mode_forced: 2
  2629.       ems_mode_external: 3
  2630.       ems_mode_vpp: 4
  2631.       ems_mode_microgrid: 8
  2632.     action:
  2633.       - service: modbus.write_register
  2634.         data_template:
  2635.           hub: SungrowSHx
  2636.           slave: !secret sungrow_modbus_slave_inv2
  2637.           address: 13049 # reg 13050
  2638.           value: >
  2639.            {% if is_state('input_select.set_sg_2_ems_mode', "Self-consumption mode (default)") %}
  2640.               {{ems_mode_self_consume}}
  2641.             {% elif is_state('input_select.set_sg_2_ems_mode', "Forced mode") %}
  2642.               {{ems_mode_forced}}
  2643.             {% elif is_state('input_select.set_sg_2_ems_mode', "External EMS") %}
  2644.               {{ems_mode_external}}
  2645.             {% elif is_state('input_select.set_sg_2_ems_mode', "VPP") %}
  2646.               {{ems_mode_vpp}}
  2647.             {% elif is_state('input_select.set_sg_2_ems_mode', "MicroGrid") %}
  2648.               {{ems_mode_microgrid}}
  2649.             {% else %}
  2650.               {{ems_mode_self_consume}}
  2651.             {% endif %}
  2652.     mode: single
  2653.  
  2654.   - id: "automation_sungrow_inverter_2_export_power_limit_mode_update"
  2655.     alias: "sungrow inverter 2 export power limit mode update"
  2656.     description: "Updates Enable/Disable for export power limit mode"
  2657.     trigger:
  2658.       - platform: state
  2659.         entity_id:
  2660.          - sensor.export_power_limit_mode_raw_2
  2661.     condition:
  2662.       - condition: template
  2663.         value_template: "{{ not is_state('sensor.export_power_limit_mode_raw_2', 'unavailable') }}"
  2664.     action:
  2665.       - service: input_select.select_option
  2666.         target:
  2667.           entity_id: input_select.set_sg_2_export_power_limit_mode
  2668.         data:
  2669.           option: >
  2670.            {% if ((states('sensor.export_power_limit_mode_raw_2') | int(default=0)) == 0x00AA) %}
  2671.               Enabled
  2672.             {% elif ((states('sensor.export_power_limit_mode_raw_2') | int(default=0)) == 0x0055) %}
  2673.               Disabled
  2674.             {% endif %}
  2675.     mode: single
  2676.  
  2677.   - id: "automation_sungrow_export_power_limit_mode"
  2678.     alias: "sungrow inverter 2 export power limit mode"
  2679.     description: "Set export power limit mode"
  2680.     trigger:
  2681.       - platform: state
  2682.         entity_id:
  2683.          - input_select.set_sg_2_export_power_limit_mode
  2684.     condition: []
  2685.     variables:
  2686.       export_limit_enable: 0xAA
  2687.       export_limit_disable: 0x55
  2688.     action:
  2689.       - service: modbus.write_register
  2690.         data_template:
  2691.           hub: SungrowSHx
  2692.           slave: !secret sungrow_modbus_slave_inv2
  2693.           address: 13086 # reg 13087
  2694.           value: >
  2695.            {% if is_state('input_select.set_sg_2_export_power_limit_mode', "Enabled") %}
  2696.               {{export_limit_enable}}
  2697.             {% elif is_state('input_select.set_sg_2_export_power_limit_mode', "Disabled") %}
  2698.               {{export_limit_disable}}
  2699.             {% else %}
  2700.               {{export_limit_disable}}
  2701.             {% endif %}
  2702.     mode: single
  2703.  
  2704.   - id: "automation_sungrow_inverter_2_export_power_limit_update"
  2705.     alias: "sungrow inverter 2 export power limit update"
  2706.     description: "Updates export power limit slider"
  2707.     trigger:
  2708.       - platform: state
  2709.         entity_id:
  2710.          - sensor.export_power_limit_2
  2711.     condition: []
  2712.     action:
  2713.       - service: input_number.set_value
  2714.         target:
  2715.           entity_id: input_number.set_sg_2_export_power_limit
  2716.         data:
  2717.           value: "{{ states('sensor.export_power_limit_2') }}"
  2718.     mode: single
  2719.  
  2720.   - id: "automation_sungrow_inverter_2_set_export_power_limit"
  2721.     alias: "sungrow inverter 2 export power limit"
  2722.     description: "Sets export power limit"
  2723.     trigger:
  2724.       - platform: state
  2725.         entity_id:
  2726.          - input_number.set_sg_2_export_power_limit
  2727.     condition: []
  2728.     action:
  2729.       - service: modbus.write_register
  2730.         data_template:
  2731.           hub: SungrowSHx
  2732.           slave: !secret sungrow_modbus_slave_inv2
  2733.           address: 13073 # reg 13074
  2734.           value: "{{ states('input_number.set_sg_2_export_power_limit') }}"
  2735.     mode: single
  2736.  
  2737.   - id: "automation_sungrow_inverter_2_update_ems_mode_input_select_update"
  2738.     alias: "sungrow inverter 2 update EMS mode input select update"
  2739.     description: "Updates EMS mode input select"
  2740.     trigger:
  2741.       - platform: state
  2742.         entity_id:
  2743.          - sensor.ems_mode_selection_2
  2744.     condition:
  2745.       - condition: template
  2746.         value_template: "{{ not is_state('sensor.ems_mode_selection_2', 'unavailable') }}"
  2747.     action:
  2748.       - service: input_select.select_option
  2749.         target:
  2750.           entity_id: input_select.set_sg_2_ems_mode
  2751.         data:
  2752.           option: "{{ states('sensor.ems_mode_selection_2') }}"
  2753.     mode: single
  2754.  
  2755.   - id: "automation_sungrow_inverter_2_update_battery_forced_charge_discharge_power"
  2756.     alias: "sungrow inverter 2 update battery forced charge discharge power"
  2757.     description: "Sets battery forced charge discharge power"
  2758.     trigger:
  2759.       - platform: state
  2760.         entity_id:
  2761.          - input_number.set_sg_2_forced_charge_discharge_power
  2762.     condition: []
  2763.     action:
  2764.       - service: modbus.write_register
  2765.         data_template:
  2766.           hub: SungrowSHx
  2767.           slave: !secret sungrow_modbus_slave_inv2
  2768.           address: 13051 # reg 13052
  2769.           value: "{{ states('input_number.set_sg_2_forced_charge_discharge_power') | int}}"
  2770.     mode: single
  2771.  
  2772.   - id: "automation_sungrow_inverter_2_update_battery_forced_charge_discharge_power_input_slider_update"
  2773.     alias: "sungrow inverter 2 update battery forced charge discharge power input slider update"
  2774.     description: "Updates battery forced charge discharge power input slider"
  2775.     trigger:
  2776.       - platform: state
  2777.         entity_id:
  2778.          - sensor.battery_forced_charge_discharge_power_2
  2779.     condition: []
  2780.     action:
  2781.       - service: input_number.set_value
  2782.         target:
  2783.           entity_id: input_number.set_sg_2_forced_charge_discharge_power
  2784.         data:
  2785.           value: "{{ states('sensor.battery_forced_charge_discharge_power_2') }}"
  2786.     mode: single
  2787.  
  2788.   - id: "automation_sungrow_inverter_2_update_battery_max_charge_power"
  2789.     alias: "sungrow inverter 2 update battery max charge power"
  2790.     description: "Sets battery max charge power"
  2791.     trigger:
  2792.       - platform: state
  2793.         entity_id:
  2794.          - input_number.set_sg_2_battery_max_charge_power
  2795.     condition: []
  2796.     action:
  2797.       - service: modbus.write_register
  2798.         data_template:
  2799.           hub: SungrowSHx
  2800.           slave: !secret sungrow_modbus_slave_inv2
  2801.           address: 33046 # reg 33047
  2802.           value: "{{ states('input_number.set_sg_2_battery_max_charge_power') |float /10 |int}}"
  2803.     mode: single
  2804.  
  2805.   - id: "automation_sungrow_inverter_2_update_battery_max_charge_power_input_slider_update"
  2806.     alias: "sungrow inverter 2 update battery max charge power input slider update"
  2807.     description: "Updates battery max charge power input slider"
  2808.     trigger:
  2809.       - platform: state
  2810.         entity_id:
  2811.          - sensor.battery_max_charge_power_2
  2812.     condition: []
  2813.     action:
  2814.       - service: input_number.set_value
  2815.         target:
  2816.           entity_id: input_number.set_sg_2_battery_max_charge_power
  2817.         data:
  2818.           value: "{{ states('sensor.battery_max_charge_power_2') }}"
  2819.     mode: single
  2820.  
  2821.   - id: "automation_sungrow_inverter_2_update_battery_max_discharge_power"
  2822.     alias: "sungrow inverter 2 update battery max discharge power"
  2823.     description: "Sets battery max discharge power"
  2824.     trigger:
  2825.       - platform: state
  2826.         entity_id:
  2827.          - input_number.set_sg_2_battery_max_discharge_power
  2828.     condition: []
  2829.     action:
  2830.       - service: modbus.write_register
  2831.         data_template:
  2832.           hub: SungrowSHx
  2833.           slave: !secret sungrow_modbus_slave_inv2
  2834.           address: 33047 # reg 33048
  2835.           value: "{{ states('input_number.set_sg_2_battery_max_discharge_power')  |float /10 |int}}"
  2836.     mode: single
  2837.  
  2838.   - id: "automation_sungrow_inverter_2_update_battery_max_discharge_power_input_slider_update"
  2839.     alias: "sungrow inverter 2 update battery max discharge power input slider update"
  2840.     description: "Updates battery max discharge power input slider"
  2841.     trigger:
  2842.       - platform: state
  2843.         entity_id:
  2844.          - sensor.battery_max_discharge_power
  2845.     condition: []
  2846.     action:
  2847.       - service: input_number.set_value
  2848.         target:
  2849.           entity_id: input_number.set_sg_2_battery_max_discharge_power
  2850.         data:
  2851.           value: "{{ states('sensor.battery_max_discharge_power') }}"
  2852.     mode: single
  2853.  
  2854.   - id: "automation_sungrow_inverter_2_update_battery_charging_start_power"
  2855.     alias: "sungrow inverter 2 update battery charging start power"
  2856.     description: "Sets battery charging start power"
  2857.     trigger:
  2858.       - platform: state
  2859.         entity_id:
  2860.          - input_number.set_sg_2_battery_charging_start_power
  2861.     condition: []
  2862.     action:
  2863.       - service: modbus.write_register
  2864.         data_template:
  2865.           hub: SungrowSHx
  2866.           slave: !secret sungrow_modbus_slave_inv2
  2867.           address: 33148 # reg 33149
  2868.           value: "{{ states('input_number.set_sg_2_battery_charging_start_power') |float /10 |int}}"
  2869.     mode: single
  2870.  
  2871.   - id: "automation_sungrow_inverter_2_update_battery_charging_start_power_input_slider_update"
  2872.     alias: "sungrow inverter 2 update battery charging start power input slider update"
  2873.     description: "Updates battery charging start power input slider"
  2874.     trigger:
  2875.       - platform: state
  2876.         entity_id:
  2877.          - sensor.battery_charging_start_power
  2878.     condition: []
  2879.     action:
  2880.       - service: input_number.set_value
  2881.         target:
  2882.           entity_id: input_number.set_sg_2_battery_charging_start_power
  2883.         data:
  2884.           value: "{{ states('sensor.battery_charging_start_power') }}"
  2885.     mode: single
  2886.  
  2887.   - id: "automation_sungrow_inverter_2_update_battery_discharging_start_power"
  2888.     alias: "sungrow inverter 2 update battery discharging start power"
  2889.     description: "Sets battery discharging start power"
  2890.     trigger:
  2891.       - platform: state
  2892.         entity_id:
  2893.          - input_number.set_sg_2_battery_discharging_start_power
  2894.     condition: []
  2895.     action:
  2896.       - service: modbus.write_register
  2897.         data_template:
  2898.           hub: SungrowSHx
  2899.           slave: !secret sungrow_modbus_slave_inv2
  2900.           address: 33149 # reg 33150
  2901.           value: "{{ states('input_number.set_sg_2_battery_discharging_start_power') |float /10 | int}}"
  2902.     mode: single
  2903.  
  2904.   - id: "automation_sungrow_inverter_2_update_battery_discharging_start_power_input_slider_update"
  2905.     alias: "sungrow inverter 2 update battery discharging start power input slider update"
  2906.     description: "Updates battery discharging start power input slider"
  2907.     trigger:
  2908.       - platform: state
  2909.         entity_id:
  2910.          - sensor.battery_discharging_start_power_2
  2911.     condition: []
  2912.     action:
  2913.       - service: input_number.set_value
  2914.         target:
  2915.           entity_id: input_number.set_sg_2_battery_discharging_start_power
  2916.         data:
  2917.           value: "{{ states('sensor.battery_discharging_start_power_2') }}"
  2918.     mode: single
  2919.  
  2920.   - id: "automation_sungrow_inverter_2_global_mpp_scan_manual_update"
  2921.     alias: "sungrow inverter 2 global mpp scan manual update"
  2922.     description: "Updates Enable/Disable for global mpp scan manual"
  2923.     trigger:
  2924.       - platform: state
  2925.         entity_id:
  2926.          - sensor.global_mpp_scan_manual_raw_2
  2927.     condition:
  2928.       - condition: template
  2929.         value_template: "{{ not is_state('sensor.global_mpp_scan_manual_raw_2', 'unavailable') }}"
  2930.     action:
  2931.       - service: input_select.select_option
  2932.         target:
  2933.           entity_id: input_select.set_sg_2_global_mpp_scan_manual
  2934.         data:
  2935.           option: >
  2936.            {% if ((states('sensor.global_mpp_scan_manual_raw_2') | int(default=0)) == 0x00AA) %}
  2937.               Enabled
  2938.             {% elif ((states('sensor.global_mpp_scan_manual_raw_2') | int(default=0)) == 0x0055) %}
  2939.               Disabled
  2940.             {% endif %}
  2941.     mode: single
  2942.  
  2943.   - id: "automation_sungrow_global_2_mpp_scan_manual"
  2944.     alias: "sungrow inverter 2 global mpp scan manual"
  2945.     description: "Set global mpp scan manual"
  2946.     trigger:
  2947.       - platform: state
  2948.         entity_id:
  2949.          - input_select.set_sg_2_global_mpp_scan_manual
  2950.     condition: []
  2951.     variables:
  2952.       export_limit_enable: 0xAA
  2953.       export_limit_disable: 0x55
  2954.     action:
  2955.       - service: modbus.write_register
  2956.         data_template:
  2957.           hub: SungrowSHx
  2958.           slave: !secret sungrow_modbus_slave_inv2
  2959.           address: 30229 # reg 30230
  2960.           value: >
  2961.            {% if is_state('input_select.set_sg_2_global_mpp_scan_manual', "Enabled") %}
  2962.               {{export_limit_enable}}
  2963.             {% elif is_state('input_select.set_sg_2_global_mpp_scan_manual', "Disabled") %}
  2964.               {{export_limit_disable}}
  2965.             {% else %}
  2966.               {{export_limit_disable}}
  2967.             {% endif %}
  2968.     mode: single
  2969.  
  2970. # Usage: Use these scripts to simplify automations
  2971. # Example (Adjust to your needs with appropriate trigger):
  2972. # automation:
  2973. #  - alias: Forced Battery Charging Management
  2974. #    description: "Manages forced battery charging during cheapest hours."
  2975. #   trigger:
  2976. #      - platform: state
  2977. #        entity_id:
  2978. #          - binary_sensor.cheapest_hours_for_charging_timer
  2979. #    action:
  2980. #      - choose:
  2981. #          - conditions:
  2982. #              - condition: state
  2983. #                entity_id: binary_sensor.cheapest_hours_for_charging_timer
  2984. #                state: 'on'
  2985. #            sequence:
  2986. #              - service: script.sg_forced_charge_battery_mode
  2987. #          - conditions:
  2988. #              - condition: state
  2989. #                entity_id: binary_sensor.cheapest_hours_for_charging_timer
  2990. #                state: 'off'
  2991. #            sequence:
  2992. #              - service: script.sg_self_consumption_mode
  2993.  
  2994. script:
  2995.   sg_2_set_forced_discharge_battery_mode:
  2996.     sequence:
  2997.       - service: input_select.select_option
  2998.         data:
  2999.           entity_id: input_select.set_sg_2_ems_mode
  3000.           option: "Forced mode"
  3001.       - service: input_select.select_option
  3002.         data:
  3003.           entity_id: input_select.set_sg_2_battery_forced_charge_discharge_cmd
  3004.           option: "Forced discharge"
  3005.       # Uncomment notify service lines below for push notifications to mobile devices
  3006.       # - service: notify.notify
  3007.       #   data:
  3008.       #     title: "Forced Battery Discharge"
  3009.       #     message: "Switched to Forced Battery Discharge mode"
  3010.  
  3011.   sg_2_set_forced_charge_battery_mode:
  3012.     sequence:
  3013.       - service: input_select.select_option
  3014.         data:
  3015.           entity_id: input_select.set_sg_2_ems_mode
  3016.           option: "Forced mode"
  3017.       - service: input_select.select_option
  3018.         data:
  3019.           entity_id: input_select.set_sg_2_battery_forced_charge_discharge_cmd
  3020.           option: "Forced charge"
  3021.  
  3022.   sg_2_set_battery_bypass_mode:
  3023.     sequence:
  3024.       - service: input_select.select_option
  3025.         data:
  3026.           entity_id: input_select.set_sg_2_ems_mode
  3027.           option: "Forced mode"
  3028.       - service: input_select.select_option
  3029.         data:
  3030.           entity_id: input_select.set_sg_2_battery_forced_charge_discharge_cmd
  3031.           option: "Stop (default)"
  3032.  
  3033.   sg_2_set_self_consumption_mode:
  3034.     sequence:
  3035.       - service: input_select.select_option
  3036.         data:
  3037.           entity_id: input_select.set_sg_2_ems_mode
  3038.           option: "Self-consumption mode (default)"
  3039.       - service: input_select.select_option
  3040.         data:
  3041.           entity_id: input_select.set_sg_2_battery_forced_charge_discharge_cmd
  3042.           option: "Stop (default)"
  3043.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement