LED Tide Display (help needed)

Hi, I’m trying to display the current tide height on a WLED led strip.
I have the tide information in home assistant and WLED integration installed and I can control the LED strip from Home Assistant, but I have no idea how to display the information.
I would like to basically divide the strip into 6 or 12 sections and light up the bottom section for low tide and then each consecutive section as the tide rises. ( I hope this makes sense)
I know the basics of turning stuff on and off with automations, but I have no idea where to start with this.
Any help would be appreciated.

Can I suggest reading the How to ask a good question FAQ then helping us to help you with more details:

  • How are you calculating the tide state?
    I’m a dinghy sailor so know about XTide, harmonics, etc but (this far…) have only seen integrations that scrape an external website for images. That works for a web page, but a depth/ height/ length sensor is really needed here.
    A goal to work to here is a template sensor which gives a scaled number that can be used for graphing - this could be a web scrape, a calculation, a Python API call, an existing integration - what ever works (I’ve got the harmonics data for my local bay so scraping feels a poor solution).

    • test and develop using the Developer Tools Template editor fitst to get a calculation of the form {{ now().hour }}:{{ now().minute }}
    • create a template sensor (I use a separate templates.yaml) and set it to update at sensible intervals from the calculation
  • A quick look at the WLED FAQ and forum didn’t find any bar graph references. You can split a strip into segments and address them separately, which might work.
    A nasty hack would be to simply reduce the number of pixels in the string with a WLED command!
    OFF, reduce Length, ON.

  • Tasmota might be easier - there are bar graph references in the wiki, as I built a LED clock and noticed the commands. Worst case - write something for ESPhome.

Hi, thanks for the reply.
I use the worldtides.info api integration to get the tide data.
Using tasmota is not a problem as I can reflash the wemos I’m using with tasmota.

I am going to try and get something working, but the template part might be a problem.
I’ve tried using templates in the past, but the formatting is a problem, I could not even get an example to work, but I will try.

I have made some progress.
I have flashed the wemos with tasmota and can now control the individual leds via mqtt.
I have figured out how to calculate the number of led’s that need to be lit and can get the code working in developer tools → template.
The problem now is to get all of this working in a template.
So far I have the following:


Minutes to high tide{% set th = (state_attr('sensor.worldtidesinfo', 'high_tide_time_utc') | as_datetime - now()).total_seconds() %}
{{ (th / 60) | round(0) }}

minutes to low tide{% set tl = (state_attr('sensor.worldtidesinfo', 'low_tide_time_utc') | as_datetime - now()).total_seconds() %}
{{ (tl / 60) | round(0) }}
{% if tl > th %}rising
{% else %}falling
{% endif %}

tide difference{% set th1 = ((state_attr('sensor.worldtidesinfo', 'high_tide_time_utc') | as_datetime ) - (state_attr('sensor.worldtidesinfo', 'low_tide_time_utc') | as_datetime )).total_seconds() %}
{% if th1 < 0 %}
{% set th1 = (th1 * -1) %}
{% else %}
{% endif %}
{{ (th1 / 60) | round(0) }}
Minutes to high tide{% set th2 = (state_attr('sensor.worldtidesinfo', 'high_tide_time_utc') | as_datetime - now()).total_seconds() %}
{{ (th2 / 60) | round(0) }}
Leds lit {{ 10 - ((((th2/th1) * 100) / 10) | round(0))}}

It gives me the desired result in developer tools, but I’m not sure what the next step is to get the info into a sensor.

Hi,
For my own sensors, getting a test calculation in the dev tools was the hard bit.

I’d suggest:

  • Create a template sensor from the dev tools template, and test it.
    Units come from const.py definition, although you might fudge it and keep 1-12 as the number of LEDs.
    Note - my example is a separate file included in configurations.yaml.
  • Create an automation that triggers when the template changes, and sets the MQTT - not done this bit exactly myself.
# templates.yaml
# no "template:" here as in configuration.yaml

- trigger:
    - event: start
      platform: homeassistant
    - platform: event
      event_type: event_template_reloaded
    - platform: time_pattern
      # set how often the value needs to change here
      hours:   05
      minutes: 05
  sensor:
    - name: Test Sensor
      state: "{{ (calculation goes here)) }}"
      unit_of_measurement: "LENGTH_METERS"    # check height mesurement?
      state_class: "measurement"
      icon: "mdi:waves"

Hope this helps,

James

Hi, I’ve made some progress, so far this is what I have:

The sensor.tide_leds determine how many leds should be lit and the sensor.state_of_the_tide change to 0,100,0 for the color green if the tide is rising and 100,0,0 if the tide is falling.

I can control the individual leds with the following code:

service: mqtt.publish
data:
  topic: cmnd/neows2812/led1
  payload: 0,100,0
  qos: '2'
  retain: true

Now I just need a way to use these values to turn the right amount of leds on and the right color, but I’m not sure how to do it.
I suspect I need to use a script or automation.