jmcollin78 / solar_optimizer

The Solar Optimizer integration for Home Assistant starts and stops your equipments depending on the Solar net production
MIT License
53 stars 10 forks source link

Solar optimiser not manage button entity (only swtch for now) #21

Open floppy84 opened 6 months ago

floppy84 commented 6 months ago

I'm trying to implement your integration for charging my renault EV, controlled by a lektrico terminal. This terminal doesn't have a switch entity to activate or stop charging, but a button entity: button.1p7k_charge_start.

So when I add your integration I get this message: Invalid config for [solar_optimizer]: Entity button.1p7k_charge_start belongs to domain button, expected ['input_boolean', 'switch', 'humidifier', 'climate'] for dictionary value @ data['solar_optimizer']['devices'][0]['entity_id']. Got 'button.1p7k_charge_start'. (See /config/configuration.yaml, line 29).

Is it possible to handle button entity

regards

jmcollin78 commented 6 months ago

Humm, yes this is a good point. I will add that.

If you are a little in a hurry you can create a virtual switch (with template) that controls the button.

MrBLJ commented 2 weeks ago

Humm, yes this is a good point. I will add that.

If you are a little in a hurry you can create a virtual switch (with template) that controls the button.

@floppy84 : As mentionned by @jmcollin78 here's how you can do that. It's quite recent for me so don't hesitate to highlight anything that seems wrong :

  1. Create a switch that triggers a script. The only variable you should need is what I've called BLE_charge_button
switch:
  - platform: template
    switches:
      titine_ble_charger:
        value_template: "{{ is_state('binary_sensor.titine_charging', 'on') }}"
        turn_on:
          service: script.turn_on
          target:
            entity_id: script.control_tesla_charge
          data:
            variables:
              BLE_charge_button: button.tesla_ble_mqtt_model_3_start_charging
              data_update_button: button.titine_force_data_update
              last_data_update_sensor : sensor.titine_data_last_update_time
        turn_off:
          service: script.turn_on
          target:
            entity_id: script.control_tesla_charge
          data:
            variables:
              BLE_charge_button: button.tesla_ble_mqtt_model_3_stop_charging
              data_update_button: button.titine_force_data_update
              last_data_update_sensor : sensor.titine_data_last_update_time
  1. Create the script. Again, in your case, only the first action should be needed :
    
    alias: Control Tesla Charge
    sequence:
    - service: button.press
    target:
      entity_id: "{{ BLE_charge_button }}"
    data: {}
    - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
    - service: button.press
    target:
      entity_id: "{{ data_update_button }}"
    data: {}
    - wait_template: >-
      {{ not (is_state(last_data_update_sensor, 'unknown') or
      is_state(last_data_update_sensor, 'unavailable')) }}
    timeout: "00:02:00"
    continue_on_timeout: false
    - wait_template: >-
      {{ as_timestamp(now()) - as_timestamp(states(last_data_update_sensor)) <
      10 }}
    timeout: "00:02:00"
    description: ""
    icon: mdi:ev-plug-type2