Integrating two codes to have an automated/manual mode

hello,

I am working on a project to automate my blinds. I already have the ability to control my blinds with physical buttons as well as virtual buttons in my home assistant. But now I want to introduce a code I found online that controls the blinds with the sun position. I want to be able to choose which mode I want, so when its in automated mode, my blinds will be set to the sun position, and when it’s in manual mode, I can adjust with the code I already have.
I am not really familiar with the Yaml code, so I hope someone of you can help me with this.
and also sorry if my English is not that good.
the link to the article about automated blinds with sun positioning:

here my existing code:

services:
    - service: control_blind
      variables:
        target: int
      then:
        - stepper.set_target:
            id: my_stepper
            target: !lambda 'return target;'
        - sensor.template.publish:
            id: position
            state: !lambda 'return target;'

captive_portal:
    
stepper:
  - platform: uln2003
    id: my_stepper
    pin_a: GPIO26
    pin_b: GPIO25
    pin_c: GPIO33
    pin_d: GPIO32
    max_speed: 250 steps/s

binary_sensor:
  - platform: gpio
    pin: GPIO12
    name: "Blinds up"
    id: physical_control_up
    on_press:
      then:
      - stepper.set_target:
          id: my_stepper
          target: 6000
      - sensor.template.publish:
          id: position
          state: !lambda return id(my_stepper).target_position;

  - platform: gpio
    pin: GPIO14
    name: "Blinds stop"
    id: physical_control_stop
    on_release:
      then:
      - stepper.set_target:
          id: my_stepper
          target: !lambda return id(my_stepper).current_position;
      - sensor.template.publish:
            id: position
            state: !lambda return id(my_stepper).current_position;

  - platform: gpio
    pin: GPIO27
    name: "Blinds down"
    id: physical_control_down
    on_press:
      then:
      - stepper.set_target:
          id: my_stepper
          target: 0
      - sensor.template.publish:
            id: position
            state: !lambda return id(my_stepper).target_position;

cover:
  - platform: template
    name: "My Blind"
    id: my_blind
    device_class: blind
    open_action:
      - stepper.set_target:
          id: my_stepper
          target: 6000
      - sensor.template.publish:
          id: position
          state: !lambda return id(my_stepper).target_position;
    close_action:
      - stepper.set_target:
          id: my_stepper
          target: 0
      - sensor.template.publish:
            id: position
            state: !lambda return id(my_stepper).target_position;
    stop_action:
      - stepper.set_target:
          id: my_stepper
          target: !lambda return id(my_stepper).current_position;
      - sensor.template.publish:
            id: position
            state: !lambda return id(my_stepper).current_position;
    optimistic: true
    assumed_state: true

sensor:
  - platform: template
    name: "My Blind Position"
    id: position

I have done a similar thing, my blinds automatically close just before sunset, this is done using the trigger sun, either sunset or sun rise. Once you have this working, I added a toggle helper called blind auto, if this is on then the blinds close on the the sun command, if it is off then they don’t and I have to do them manually, this is done by adding a condition to the sun automation where you see if the toggle is on or off.

Thanks for your reply. I have tried your solution, and it works, but I want to be able to control my blinds automatically in the sun position with the code from the post mentioned, so I have just enough shadow on my desk where I work but not fully closed.

Not a problem, I do this with my lounge curtain, you need to know the elevation of the sun and when you want the shade, and also the position of your blind, that is just playing until it’s right, then write something like this… using numeric state and sun.

alias: Ln-Set-Curtain-When-Sun-Low
description: ""
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: 18.6
condition: []
action:
  - device_id: 14d3863976d7b597a8a47452c0efe291
    domain: cover
    entity_id: cover.lounge_curtain_cover
    type: set_position
    position: 80
mode: single

I found the elevation of the sun by using developer tools and states as below.

If you do it roughly the time of day you want it will give you an idea of the elevation needed.

i tried to do this but wasnt succesful. i cant select my blinds to set at specific position. i only have open, close and stop?

My code is meant for home assistant, it will not work with esphome.

Your method will not work, as the position of the sun in the sky in a given hour will be completely different for every season. With the code I made you don’t have to worry about that, because I use a mathematical formula to guarantee a certain amount of shade.

Hey, thanks for replying.
I used the blueprint from your code and chose the entitie from my blinds, but they are not moving.
Is this because they are made with esphome, or do you have a solution for that?

The blueprint works with any cover entity. Whether that entity is provided by esphome or some other integration doesnt matter. In my previous comment I meant that you can’t simply copy paste the YAML code into esphome, it won’t work.

To debug the blueprint you will have to look at the automation trace and see where it terminates (go the automation, click on traces). In most cases where the cover didnt move it was because the distance ‘d’ was set to 0 (this means 100% shade all the time). If you need help debugging the automation you should download and post your trace in blueprint thread