i2c: sda: GPIO18 scl: GPIO17 globals: - id: total_pulses type: int restore_value: true initial_value: '0' binary_sensor: - platform: gpio pin: number: GPIO15 mode: INPUT_PULLDOWN name: "Anchor Chain Sensor" id: anchor_chain_sensor filters: - delayed_on: 1ms - delayed_off: 10ms on_press: then: - lambda: |- if (id(anchor_winch_up).state > 2.0) { if (id(total_pulses) > 0) { id(total_pulses) -= 1; } } else { id(total_pulses) += 1; } sensor: - platform: template name: "Chain Length Deployed" id: chain_length_sensor unit_of_measurement: "m" icon: "mdi:anchor" update_interval: 1s lambda: |- // Calculate the chain length in meters by multiplying the // total pulse count by the distance per pulse calibration value const float distance_per_pulse = 0.2; // in meters, adjust as needed return id(total_pulses) * distance_per_pulse; - platform: ina219 address: 0x40 shunt_resistance: 0.1 ohm id: ina_sensor bus_voltage: name: "anchor winch up" id: anchor_winch_up accuracy_decimals: 1 max_voltage: 26.0V max_current: 3.2A update_interval: 1s switch: - platform: template name: "Reset Chain Length" id: reset_chain_length turn_on_action: - lambda: |- id(total_pulses) = 0; - delay: 1s - switch.turn_off: reset_chain_length