How can I set something to happen if a sensor moves from a value to another value?

I need to know that the trim/tilt sensor on my boat is working to allow an automation to proceede. This is the automation:

#Motorheis opp og ned
  - platform: template
    name: "Motorheis helt ned"
    id: motorheisheltned
    turn_on_action:
      - wait_until:
          condition:
            sensor.in_range:
              id: tiltsensor
              below: 50.0
          timeout: 45s
      - switch.turn_off: motorheisopp
      - switch.turn_off: tiltopp
      - switch.turn_off: motorheisopp
      - delay: 500ms
      - switch.turn_on: hekkrele2
      - switch.turn_on: motorheisoppned
      - switch.turn_on: motorheisned
      - delay: 25s
      - switch.turn_off: hekkrele2
      - switch.turn_off: motorheisned
      - switch.turn_off: motorheisoppned

This waits until the trim sensor shows below 50 to fire the automation (by using wait until in the turn on action). But there is one problem with this, which may be quite expensive: If the trim sensor has locked up in for instance 40, but the outboard motor in reality is all the way up (which is above 100), I will damage my steering cylinder. So to make sure that can never happen (Murphy is very much a crew member on my boat, and his law is ruthless…) I would like to have a condition that says that when the sensor goes from above 60 to below 50 then it should fire. Because that means that the sensor isn’t stuck.

Can somebody please tell me if this is possible, and if it is help me with how to do it?

Can you share your tilt sensor yaml?

Of course, and thanks for answering! It’s a simple MQTT subscribe sensor. The value originally comes from the Suzuki engine interface over NMEA2000, and that value goes to SignalK (boat information server), which sends it to the MQTT broker. It is filtered to go invalid after ten seconds, so I don’t stop the outboard motor (which kills the data from the Suzuki engine interface) and then tilt it so much that it will interfere with with jackplate operation. “Motorheis” is Norwegian for jack plate, which moves the outboard motor up and down on the transom.

The expire_after is just for display in HomeAssistant (which I was told here in no uncertain terms when I thought that also applied for the sensor it self… :rofl:).

#Tilt
  - platform: mqtt_subscribe
    name: "Tiltsensor"
    id: tiltsensor
    topic: madmax/trim
    expire_after: 10s
    filters:
      - timeout:
          timeout: 10s

I can’t think of anything clever to do this… :slight_smile:

I would probably:

  • create a boolean global that gets set when the sensor goes above 60 (use on_value: in your tilt sensor)
  • test for that global as well as below: 50
  • reset the global at an appropriate time (in your automation maybe?)

Thanks! I’ll leave it for a couple of days in case somebody else has an easier solution. If not I’ll try to make template sensors that creates booleans.

Interesting topic. For me maoin question is - what is exactly:

If sensor reports 61, then 49 - it is a case.
If sensor reports 61, 55, then 48 - ?
If intermidiate values allowed - what is a timeframe for going from above 60 to below 50 ?

Thanks for answering! I don’t really care about the intermediate values. I want to see if the sensor goes from above 60 to below 50 within the set wait time. So if sensor report 61, 55, then 48, it’s still a case.

The timeframe is, as it is now, set to the timeout for the turn_on_action, which is 45 seconds. But of course tilting the outboard motor does not take that long, it’s just that I want to wait long enough for me to have time to tilt it before lowering it on the transom with the jackplate.

So if I trim it from 90-99 (the top, the sensor isn’t totally accurate) to 60, the first of the requirements is met. If I then trim it futher down to 50 within the time that’s left it will have met the second of the requirements. So as long as it goes from 60 to 50 before the 45 seconds have gone by, the automation should start.

Edit: Changed a few things, hopefully to make it more clear… :grin:

Id make sure you test well. The (on_value above/below, in_range) can all be kind of finicky about when it will or wont trigger. I dont recall each quirk but just keep in mind that it only triggers when that value is above and then goes below that number. You could have issues if your sensor is below that number during boot or a restart. I would just thoroughly test different scenarios before final install. Those sensor configurations seem to cause a lot of people problems in my experience.

Something else, its hard to beat the dependability of a good old micro switch or limit switch to check if your trim sensor is locked up, malfunctioning, or whatever.

What are you trying to do exactly? Im having a hard time picturing what your doing with a boat. Do you have any pictures or anything?

I have just solved it with Node-RED. :grin:

And why? Well, partly laziness, partly fun. The finished setup will do this when I press on a switch card in Lovelace:

  1. Connect the ignition (whitout it the engine interface doesn’t send) with a relay connected to a different ESP32.

  2. Start tilting the motor down. If the motor is tilted to the top the steering will be damaged because it hits the transom when the jack plate goees down.

  3. When the tilt has gone from above 60 to below 50 within 10 seconds, the text tiltsensor is set to the permissable value, which triggers the jack plate that moves the motor vertically on the transom.

  4. When the tilt sensor in the motor goes below 10, tilting stops.

  5. After the set amount of seconds the jack plate stops. That concludes this automation, and the motor will be ready to start, wich I’m making another automation for (triggered by pressing the wireless dead man’s grip. The goal is a keyless ride with my phone as the key. But a picture is always fun, so here’s the transom. The jack plate is the part between the boat and the outboard motor with the letters “PO” visible, here it is in the bottom position. As you can see, if the motor is tilted up above a certain level, the steering cylinder and the bracket for that will hit the transom.

And for the top position I do have a limit switch, it was just difficult to place one for the bottom position.

And if you’re curious, this is the full Mad Max, ready to set crawfish pots:

Ok, now that makes more sense when i can see what you got going on. Thats a sweet little boat! Are those some kind of traps stacked up on the side?

Thanks! And yes it is. For crawfish, on a chute. I have 12 of those in a string, set them around 100 meters depth. To I set out them they are stood up on end, with the line attached, so I basically just drive them out the back. The green thing at the bough is what pulls them up. We also use the boat for deep sea fishing in the late spring, summer and early fall.

Dang! Are living the freaking dream? You get to go out and catch your own crawfish or any fish and cook it up for dinner? You down in the southern US?

Nope, a lot further to the North and East. Norway. :grin: And yes, I can. For now I still have to work on weekdays, but in four years I’ll retire and go fishing whenever I want to!

Oh wow, Norway. What a presumptuous American, huh?!?!? lol. That’s so cool, I really envy you! I live in the center of the US and it’s just flat farmland here. Got a few fishing holes but nothing where i’d really want to eat out of or at least frequently. That lifestyle has always been something I want to do. I hope you enjoy it

Yes, I do, very much, thank you! And I will even more in four years, when I retire and don’t have to waste time working! :rofl:

Excuse me? A waste of time it definitely is not! Where else is the government going to collect tax money to hand out to non working people and stupid causes?? You’re not wasting your time, oh no! You’re paying your fair share!

Good point, boss! :grin: :rofl: