Sonoff Tasmota extension for covers

pulsetime2 is used for two things.

  1. a time gap between switching from “opening” to “closing”
  2. the amount of “extra” time to make sure the system operates completely.

My window winders, take ~2 seconds from button press to actually start moving, so although in and out take 25 seconds, this is 25 seconds of movement, not including the startup time. Thus i have to run the relays for 27seconds to get a full open or close. Without the pulsetime2 moving for 2 seconds results in my windows not moving at all.

The system is simply using timing and maths to guesstimate the cover position.
So if the cover is at 100 and you ask for 24, it knows it has to move 76.
To move 76 it has to multiple pulsetimer1 * 76%, then add the pulsetime2, and then turn on the relay, wait that much time and then turn off the relay.
I maybe using 10th of a second calculations, but don’t have the code handy to check.

Since its only integer maths and truncated, the smaller the length of time, the less accuracy you will get (eg 25 seconds to open/close will only give you 25 values between 0 and 100, thus every 4 values in the 0-100 range will end up with the same result)

Steve

Thanks, with your explanation is now well for me…

About HomeAssistant i use this code to command the cover. Do you have suggestion about?

Actually the issues are:

  • i loose the status of the cover at HA reboot until i open or close the cover
    2018-04-19%2008_07_17-Home%20Assistant
  • tilt position and position are not syncronized
  • i have this error in debug

2018-04-18 17:19:06 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff02/LWT: b’Online’
2018-04-18 17:19:06 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to stat/sonoff02/RESULT
2018-04-18 17:24:25 WARNING (MainThread) [homeassistant.helpers.condition] Value cannot be processed as a number: –
2018-04-18 17:26:38 ERROR (MainThread) [homeassistant.components.cover.mqtt] UndefinedError: ‘value_json’ is undefined
2018-04-18 17:26:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/sonoff02/RESULT: b’{“Cover1”:40}’
2018-04-18 17:29:28 WARNING (MainThread) [homeassistant.helpers.condition] Value cannot be processed as a number: –
2018-04-18 17:34:31 WARNING (MainThread) [homeassistant.helpers.condition] Value cannot be processed as a number: –

This is the code that i use

cover:

  • platform: mqtt
    state_topic: “stat/sonoff02/RESULT”
    command_topic: “cmnd/sonoff02/Backlog”
    availability_topic: “tele/sonoff02/LWT”

    name: “Tenda 1”
    qos: 0
    retain: true
    payload_open: “cover ON”
    payload_close: “cover OFF”
    payload_stop: “cover 3”
    state_open: “ON”
    state_closed: “OFF”
    payload_available: “Online”
    payload_not_available: “Offline”
    optimistic: false
    value_template: ‘{{ value_json.Cover1 }}’

    tilt_command_topic: “cmnd/sonoff02/COVER”
    tilt_status_topic: “stat/sonoff02/RESULT”
    set_position_topic: “cmnd/sonoff02/COVER”
    set_position_template: ‘{{ value_json.Cover1 | is_defined }}’

    tilt_min: 5
    tilt_max: 100
    tilt_closed_value: 20
    tilt_opened_value: 50

I don’t think you have the value template correct, as its the two part response, cover and value.

I’m not an expert in the json templates, so you amy have to ask someone else about how to get that right.

Once its right, the restart should query the cover and get the correct value.

I just open another topic about

and someone suggest it, infact i’m able to have the correct cover position if i move the cover from HA or from Sonoff or manually… I don’t have the status (unknown) if i restart HA or if it loose connection with sonoff

When it works the received message is

2018-04-18 17:02:52 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/sonoff02/RESULT: b’{“Cover1”:48}’

If you have an example how you configure your HA could be fine

Works fine now adding some tricks to get the status when HA restart

A suggestion: is it possibile to set an option in order to have a different range when the awning is moved manually via physical switches?

For example: via HA/Sonoff: 0-100 , manually 200-300 so it’s possible to do something via automation based on manual/automatic movement

Thanks

Sorry, i dont understand your requirement.
The 0-100 is the percentage open.
On mine, i use the single button on the sonoff to cycle between open/stop/close/stop.

So you simply press the button on then press again to stop, or a couple of times to switch direction.

The positioning is updated, so all stays i sync.

Separate manual buttons via the sonoff could work, but the dual by default only has one button.

the idea is to understand if the position is made via HA (0-100) or if is set via manual action (200-300).

In my Dual, i connect 2 buttons so i can move the awning manually and set the position that i want. HA receive the new position.

How did you do that? Im trying the same.
Everything works but if i use the hardware button in the wall it moves but Home Assistant dindnt get new position.

this is my code

configuration.yaml

cover: !include covers.yaml

covers.yaml

  - platform: mqtt
    state_topic: "stat/sonoff02/RESULT"
    command_topic: "cmnd/sonoff02/Backlog"
    availability_topic: "tele/sonoff02/LWT"
    name: "Tenda 1"
    qos: 1
    retain: true
    payload_open: "cover ON"
    payload_close: "cover OFF"
    payload_stop: "cover 3"
    state_open: "ON"
    state_closed: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    value_template: '{{ value_json.Cover1 }}'
    set_position_topic: "cmnd/sonoff02/COVER"

automation.yaml

This is necessary due if restart/reload HA i loose current cover position, so i send a call with empty payload and mqtt return current position

 ## START Internal Automation
 - alias: Reload Cover status from unknown
   hide_entity: True
   trigger: 
     platform: homeassistant
     event: start
   condition:
     condition: state
     entity_id: cover.tenda_1
     state: unknown    
   action:
    - service: mqtt.publish
      data:
        topic: cmnd/sonoff02/COVER
        payload: ""
 ## END Internal Automation

Then I also have automation to put down/up the awning based on sun position/weather

1 Like

Quite the same of mine. I cant understand: command_topic: “cmnd/sonoff02/Backlog”

Here’s mine:

  • platform: mqtt
    name: “MQTT Cover”
    command_topic: “cmnd/sonoff2/cover”
    state_topic: “stat/sonoff2/RESULT”
    available_topic: ‘tele/sonoff2/LWT’
    qos: 0
    retain: true
    payload_open: “100”
    payload_close: “0”
    payload_stop: “stop”
    state_open: ‘{“Cover1”:ON}’
    state_closed: ‘{“Cover1”:OFF}’
    payload_available: “Online (retained)”
    #payload_not_available: “Offline”
    optimistic: true
    #value_template: ‘{{‘value.x’}}’
    set_position_topic: “cmnd/sonoff2/cover”

Can you explain this too

Hi,
testing with T1 (2 gang) shows this device is not fully supported yet (nobody had said that).
The T1 is a perfect device for covers: Has 2 relays like the Dual, and also has two buttons. Can be used as up and down. If mounted my 90°, it shows up and down in a nice manner.

I will look into it.
Dieter

I’m also interested in adding support to T1. Just got my sonoff today.

Hi guys, I don’t have a T1 so not able to test. Not sure why it shouldn’t as I kept my changes device agnostic as much as possible.

If you can tell me what the issues are, I can try to investigate and see if I can fix.

@kabongsteve, you are a genius. I´ve been looking into automating my blinds for a year now, this is almost perfect.

Is there a way to use other GPIOs as wall switches? (I use a normal wall switch with all my sonoffs basic, shorting GND and GPIO14). I´m confident soldering stuff, but I lack the ability to code.

Thanks a lot!

In theory, you can still use the standard Sonoff Tasmoto config for the extra GPIOs and set them as Buttons or Switches.
If you set an MQTT topic, then they simply send the topic and don’t act as direct buttons.
You can then use HA to activate cover via automation triggered from MQTT message.

If this doesn’t work, I think I could do some code changes, so that Switches without MQTT topics, could work in pairs, to open/close.

but this is assuming the switches are momentary action, and would start/stop the movement in the relevant direction.

Is this what you would expect?

I’m possibly looking to support switches, instead of buttons to allow for separate open/close buttons.

If i implement this, this I could add or change the MQTT messages used for the movement and thus show the operation was manual, rather than automatic.

something like this be what you’re after?

Hi guys,
I’ve checked my code and the functions it uses and I can see no reason that it shouldn’t work, assuming the standard Tasmota firmware works as expected.

But looking at his comments on this device and the UK vs US versions, and how it works, this functionality may not work at all, as the template config for this device, doesn’t seem to match what the spiel about this device suggests.

Has anyone tried his standard firmware and go the relay switching to work from mqtt or web?

Hi @kabongsteve ! Thanks for your work, right now I have a Sonoff Dual with default Tasmota firmware with both GPIO01 and GPIO03 (Serial Out and In) connected to two wall switches (not momentary), one goes up and one goes down. I can control the cover using either Home assitant with MQTT cover or switching whe wall buttons.

image

Right now the home assistant cover is working correctly but I lack the option of knowing the cover open/close percentage.

Could your firmware work with these king of wall switches?

Thanks in advance!

they are sexly what are they