Untitled

mail@pastecode.io avatar
unknown
yaml
2 years ago
1.0 kB
9
Indexable
Never
trigger:
  - platform: state
    entity_id: sensor.dellinspiron7773_battery_powerline_status
    to: ['Offline', 'Online']
    variables:
      diff: "{{ states('sensor.battery') | float(-1000) - states('input_number.start') | float(1000) }}"
action:
  - choose:
      - conditions:
          - "{{ trigger.to_state.state == 'Online' }}"
        sequence:
          - service: input_number.set_value
            data:
              value: "{{ states('sensor.battery') | float }}"
            target:
              entity_id: input_number.start
      - conditions:
          - "{{ states('input_number.start') | float >= 0 and diff > 0 }}"
        sequence:
          - service: input_number.set_value
            data:
              value: "{{ states('input_number.total') | float + diff / 100 }}"
            target:
              entity_id: input_number.total
          - service: input_number.set_value
            data:
              value: -1
            target:
              entity_id: input_number.start