ESP32 control a linear actuator with pulse feedback

I’m trying to control with an ESP32 via Home Assistant the position of a linear actuator with feedback. The linear actuator sends pulses as it travels back and forth.
Their is a total of 800 pulses from the retracted position to the fully extended position. I tried using the Pulse_counter and it counts the pulses but I cannot figure out how to automatically reverse the count depending on the direction of the actuator.
For testing I’m using two switches, open and close.
I tried using a directional variable that gets set depending on witch switch I pressed but I don’t know how to incorporate it into the Pulse_counter function. can any one help me out or suggest a different approach. Thanks

 globals:
	- id: var_actuator_direction
    type: int
    restore_value: no
    initial_value: '0' # 0=retract 1=extend

sensor:
  - platform: pulse_counter
    pin: GPIO34
    id: windowactuator1
    use_pcnt: true
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 500ms
    total:
      name: 'TCount'
  

Assuming your pulse counter works, create a new template sensor that uses lambda to increment or decrement a value base on the direction and count.

On my mobile now so can’t give you an example yaml…

Hi Daryl

I’m fairly new at this, can you provide an example? Also how do you display the content of a variable in the esp32 device page or the log file?

You can use the number component and it will show in HA.

number:
  - platform: template
    step: 1
    min_value: 0
    max_value: 800
    id: ac_pos
    optimistic: true
   
sensor:
  - platform: pulse_counter
    pin: GPIO34
    id: windowactuator1
    use_pcnt: true
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 500ms
    total:
      name: 'TCount'
    on_value: 
      then:
        - if:
            condition:
              - switch.is_on: open
            then: 
              - number.increment: ac_pos
        - if:
            condition:
              - switch.is_on: close
            then: 
              - number.decrement: ac_pos

Can you post a pic or something of your actuator? I pulled these off an adjustable bed someone was throwing away but, for the life of me I cant find any data sheet for these based on the information on the sticker.

I did figure out that white/blue are my In/Out or +/- but after testing it and extending one actuator, now I cant get it to retract. I assume it has to do with the position feedback but im not sure how this works as far as if it uses analog signals(resistance) or some other method.

Any tips/suggestions?

I would estimate that blue and brown are 24Vfor motor, others for low voltage feedback, like 5v, gnd and potentiometer output for feedback. So reversing polarity of blue and brown would drive that motor forward and backward independently of feedback.

Edit: I didn’t notice that black wire, so it has more complicated circuit. And I don’t even see white wire…

Ya, i figured out the wires for moving it but its stuck fully extended now and reversing polarity doesnt retract. Initially I had movement both ways and then I fully extended it and it wont move at all now.

I was hoping they could still be used without the feedback hooked up but, doesnt appear so.

Were you using brown and blue to drive it?

Those thinner wires are for hall effect encoder and synch. Should work without those connected.

No. I said White and Blue earlier but, I meant Brown and Blue wires are what drives the motor. Hhhmm… I extended it all the way untill it hit its internal limit switch and stopped. It wont retract now so, I was trying to figure out if it had something to do with its feedback system.

Ive only ever used “dumb” actuators and these are unfamiliar to me.

You probably hit limits too hard… Open it and try to take it back manually.

I put a link to actuator I think is wired like yours:

Although that sounds perfectly reasonable. Im not sure how its possible to hit the limit switch too hard. It operartes at 1 speed, slow!

Thanks for the docs though, ill definitely look through there. I do suspect it has something to do with the feedback or the limit switch. It probably requires a signal to release snd retract.

There was some sort of control box they plugged into but the person already threw it away and i didnt get it.

Newer opened one like this, but those 5-wire ones with feedback, don’t have any limit switch reset functionality. I suspect that when you drive these with feedback attached, control board doesn’t allow you to crash to limits at full speed.

I’m using the following actuator:

)

The two higher gage wires power the motor, the other 3 are for the hall sensor.

I’m still having problems with the espHome pulse_counter doing a forward and reverse count on the hall sensor. all a get is a continuing total pulse count. Cant seem to get it to substract the pulses when in reverse.

I hadnt considered a hall sensor being in mine, nice call! I need to just get my meter out and motivate myself!

Ive never needed or tried to use pulse_counter for 2 directions but, the documentation mentions count_mode and increment/decrement. One direction will be rising-falling for example and youd increment on that pattern. If its a falling-rising then decrement the total count.

A simpler way would be to use the extend/retract switches instead.

While extend switch is_on - then - add pulses
While retract switch is_on - then - subtract pulses

So you didn’t read my post two weeks ago?

Did you try that code from @Mikefila ?

Sure did and you referenced a potentiometer not a hal sensor…

because I didn’t see that black wire in your picture…

later I wrote:

Either way it was weeks ago, can i have a little grace for obviously forgetting?

Of course.
Also note that yours has synch to make both motors work together, so it’s little bit more complex than the one above