Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutter position wrong in Home Assistant #57

Closed
ctripodi opened this issue Aug 11, 2018 · 27 comments
Closed

Shutter position wrong in Home Assistant #57

ctripodi opened this issue Aug 11, 2018 · 27 comments

Comments

@ctripodi
Copy link

Hi @stefanbode , first of all, thank you for this great project "upgrade"!
I am using Home Assistant with this configuration (I the example available in Wiki didn't work for me):
This is my cover definition:

  • platform: mqtt
    name: "Test"
    availability_topic: "hm/tele/sonoff_cover/LWT"
    state_topic: "hm/stat/sonoff_cover/RESULT"
    command_topic: "hm/cmnd/sonoff_cover/backlog"
    value_template: '{{value_json.shutterposition1}}'
    qos: 1
    retain: true
    payload_open: "SHUTTEROPEN"
    payload_close: "SHUTTERCLOSE"
    payload_stop: "SHUTTERSTOP"
    state_open: "ON"
    state_closed: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: true
    tilt_command_topic: 'hm/cmnd/sonoff_cover/shutterposition'
    tilt_status_topic: 'hm/cmnd/sonoff_cover/shutterposition'
    set_position_topic: 'hm/cmnd/sonoff_cover/shutterposition'
    tilt_min: 0
    tilt_max: 100
    tilt_closed_value: 0
    tilt_opened_value: 100

The problem is that the current_tilt_position & current_position is not updated after use the buttoms to open or close in the web interface of Home Assistant (yellow mark), so you have 2 status forthe same Entity (red marks).
imagen
I guess that this could be solved, with the inclution of a json status update after finish the command (SHUTTEROPEN, SHUTTERCLOSE or SHUTTERSTOP) some like this (according to the real status of shutterposition1):
imagen
I am using this switches:
imagen

Thanks. Cristian

@stefanbode
Copy link
Owner

Hi Christian, yes this makes perfect sense. I also checked that this will save me some bytes if I just do it a little different. I just uploaded a new version with the change. The result is reported twice Just too complicated to fix, therefore I leave it as it is because it should not make a problem.

Here how the shutterstop will behave:

09:03:37 Shutter 0: Real Pos: 4200, Target 20000, source: Shutter, pos %: 0, direction: 1, rtcshutter: 43
09:03:39 Shutter 0: Real Pos: 6700, Target 20000, source: Shutter, pos %: 0, direction: 1, rtcshutter: 68
09:03:40 Shutter 0: Real Pos: 8700, Target 20000, source: Shutter, pos %: 0, direction: 1, rtcshutter: 88
09:03:40 CMD: shutterstop
09:03:40 SRC: Serial
09:03:40 RSL: Received Topic /shutterstop, Data Size 0, Data
09:03:40 RSL: Group 0, Index 1, Command SHUTTERSTOP, Data
09:03:40 SRC: Shutter from 0.0.0.0
09:03:40 RSL: Received Topic /shutterposition1, Data Size 2, Data 49
09:03:40 RSL: Group 0, Index 1, Command SHUTTERPOSITION, Data 49
09:03:40 lastsource 20: webgui:7
09:03:40 MQT: hm/status/sonoff/RESULT = {"shutterposition1":49}
09:03:40 MQT: hm/status/sonoff/RESULT = {"shutterposition1":49}
09:03:40 Shutter 0: Stopp Pos. 10100, relay: 0, pulsetimer: 0, rtcshutter: 101

@stefanbode
Copy link
Owner

There is also on option already to use the SENSOR data that came in with TELEPERIOD to update the position:

09:40:51 MQT: hm/status/sonoff/SENSOR = {"Time":"2018-08-13T09:40:51","Switch1":"ON","Switch2":"ON","ANALOG":{"A0":7},"SHUTTER-1":0}

@ctripodi
Copy link
Author

Hi @stefanbode sorry for the delay in the tests. I updated the firmware a few minutes ago. It is working perfect for the "field" position in Home Assistant.
I will check my cover configuration in HA due that the "field" Tilt position is not updated like the "field" position.
In resume, thanks a lot for your support! Your project is reaaly a very good improvement & complement for the project Sonoff-Tasmota

@ctripodi ctripodi reopened this Aug 17, 2018
@ctripodi
Copy link
Author

@stefanbode, I forgot the test using the switch manually & web frontend. The result of my test, It was like what @udo1toni mentioned.
I get a shutterposition update if using shutteropen, shutterclose or shutterstop, but I get no shutterposition update if switching the shutter manually or using the web frontend.
I guess that this could be solved, in the same way than before, with the inclution of a json status update after use the switch manually or using the Buttons in the web frontend.
And maybe using the INTERLOCKMASK you can update this status just for the shutter buttoms.
Regards.

@pablitofernandez
Copy link

I have the same issue as @ctripodi , I have the latest firmware flashed but the position is not reported correctly. Using a Sonoff Dual R2 here.

@stefanbode
Copy link
Owner

For the button or switches this is more complicated. Can you check if it works if you set teleperiod to 10 and unse the reported shutter position from this point.

@stefanbode
Copy link
Owner

stefanbode commented Aug 20, 2018

I Introduced a new RESULT sending all the time, if the shutter STOP moving. This will report the actual position. To be in sync with the TELEPERIOD the format is different form the "shutterpositionyy xx" stuff.

As you can see in the log I set the shutterposition to 80. This will be reported directly as RESULT = {"shutterposition1":80}. But the real position of the shutter is reported later on at:
09:50:38 RSL: RESULT = {"SHUTTER-1":80}

You will get this message also, if you change movement during operation and/or moving the shutter by hand. Hopefully this helps with your requirements.

09:50:33 RSL: Received Topic /shutterposition, Data Size 2, Data 80
09:50:33 RSL: Group 0, Index 1, Command SHUTTERPOSITION, Data 80
09:50:33 lastsource 2: webgui:7
09:50:33 SRC: Shutter
09:50:33 RSL: RESULT = {"POWER1":"ON"}
09:50:33 RSL: POWER1 = ON
09:50:33 RSL: RESULT = {"shutterposition1":80}
09:50:33 Shutter 0: Real Pos: 6100, Target 16000, source: Shutter, pos %: 30, direction: 1, rtcshutter: 2
09:50:33 CFG: Saved to flash at 3F8, Count 75, Bytes 3820
09:50:34 Shutter 0: Real Pos: 8400, Target 16000, source: Shutter, pos %: 30, direction: 1, rtcshutter: 25
09:50:35 Shutter 0: Real Pos: 10400, Target 16000, source: Shutter, pos %: 30, direction: 1, rtcshutter: 45
09:50:36 Shutter 0: Real Pos: 12400, Target 16000, source: Shutter, pos %: 30, direction: 1, rtcshutter: 65
09:50:37 Shutter 0: Real Pos: 14400, Target 16000, source: Shutter, pos %: 30, direction: 1, rtcshutter: 85
09:50:38 Shutter 0: Stopp Pos. 16000, relay: 0, pulsetimer: 0, rtcshutter: 100
09:50:38 RSL: RESULT = {"SHUTTER-1":80}
09:50:38 SRC: Shutter
09:50:38 RSL: RESULT = {"POWER1":"OFF"}
09:50:38 RSL: POWER1 = OFF
09:50:38 CFG: Saved to flash at 3F7, Count 76, Bytes 3820
09:50:43 RSL: STATE = {"Time":"2018-08-20T09:50:43","Uptime":"0T00:00:15","POWER1":"OFF","POWER2":"OFF", "Wifi":{"AP":1, "SSId":"BodeNet_Keller", "RSSI":98, "APMac":"7C:FF:4D:3D:A3:5B"}, "D
eepSleep":-1, "Heap":20960}

@pablitofernandez
Copy link

Thanks @stefanbode , with your last update It seems like is working as expected, great job! For more details this is my actual cover config in HA:

  • platform: mqtt
    name: "Persiana del dormitorio"
    availability_topic: "tele/persiana_dormitorio/LWT"
    state_topic: "tele/persiana_dormitorio/RESULT"
    command_topic: "cmnd/persiana_dormitorio/backlog"
    set_position_topic: "cmnd/persiana_dormitorio/shutterposition"
    value_template: "{{ value_json['SHUTTER-1'] }}"
    qos: 1
    retain: true
    payload_open: "SHUTTEROPEN"
    payload_close: "SHUTTERCLOSE"
    payload_stop: "SHUTTERSTOP"
    state_open: "ON"
    state_closed: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: true

@stefanbode
Copy link
Owner

Hi, these are great news. Looks like I get now more or less a stable version that is worth to request a merge request with the master branch. Thanks for your support

@B1G1
Copy link

B1G1 commented Aug 21, 2018

Hi @stefanbode,
about the new RESULT, it's very usefull to have an instant update of the current position instead of waiting 10 seconds for teleperiod update. But using the @pablitofernandez configuration in Home Assistant if I restart Home Assistant, I loose the current position until I move and stop the shutters.
I could initialize position sending a shutterposition command throug mqtt message on home assistant start event, but in that case the response is (two times)
stat/tapparellaStudio/RESULT = {"shutterposition1":100}
and based on that config we need instead
tele/tapparellaStudio/RESULT = {"SHUTTER-1":100}

Any suggestion to how solve this issue?

@pszafer
Copy link

pszafer commented Aug 22, 2018

Hi @stefanbode .
Great update!

Can you maybe add retain flag to tele/%topic%/RESULT so after HA restart it will get current position of cover?
Second, maybe I should open another issue, don't know, but after this update when I send command via web console eg. shutterclose or shutteropen Sonoff is restarting itself (reason Software Watchdog).
shutterposition 100 / shutterposition 0 is working correctly.

@stefanbode
Copy link
Owner

Ok, it gets more and more complex. Anyhow. It is not a good advise to use RESULT and retain this one. As it is done with POWER1 and POWER2 the value is retained in a special tag. Therefore it is possible to retain, but then I would introduce a new tag like the power to do this and also use the power retain flag to control if it is retained or not.

@pszafer
Copy link

pszafer commented Aug 22, 2018

Got you. So as for me don't bother about this.

Do you have same behaviour for shutterclose/shutteropen in web console?

Maybe I #undef too much things to get image lighter.

Correct reason is Software watchdog.

#ifndef _USER_CONFIG_OVERRIDE_H_
#define _USER_CONFIG_OVERRIDE_H_

#warning **** user_config_override.h: Using Settings from this File ****

// -- Master parameter control --------------------
#undef  CFG_HOLDER
#define CFG_HOLDER        4618                   // [Reset 1] Change this value to load SECTION1 configuration parameters to flash

#undef PROJECT
#define PROJECT		"cover_entrance"

#undef MODULE
#define MODULE		SONOFF_DUAL_R2

// -- Setup your own Wifi settings  ---------------
#undef  STA_SSID1
#define STA_SSID1         "SSID"             // [Ssid1] Wifi SSID

#undef  STA_PASS1
#define STA_PASS1         "SSIDPASS"     // [Password1] Wifi password

// -- Setup your own MQTT settings  ---------------
#undef  MQTT_HOST
#define MQTT_HOST         "192.168.1.5" // [MqttHost]

#undef  MQTT_PORT
#define MQTT_PORT         1883                   // [MqttPort] MQTT port (10123 on CloudMQTT)

#undef  MQTT_USER
#define MQTT_USER         "mqtt"         // [MqttUser] Optional user

#undef  MQTT_PASS
#define MQTT_PASS         "MQTTPASS"       // [MqttPassword] MQTT password

#ifdef MY_IP
#undef  WIFI_IP_ADDRESS
#define WIFI_IP_ADDRESS   "0.0.0.0"                  // Set to 0.0.0.0 for using DHCP or IP address
#endif

#undef TELE_PERIOD
#define TELE_PERIOD	300

#undef MQTT_TELE_RETAIN
#define MQTT_TELE_RETAIN     1                   // Tele messages may send retain flag (0 = off, 1 = on)

#undef USE_DOMOTICZ
#undef USE_HOME_ASSISTANT
#undef USE_KNX_WEB_MENU
#undef USE_TIMERS 
#undef USE_RULES
//#undef COUNTERDEVIDER
#undef USE_I2C
#undef USE_MHZ19
#undef USE_SENSEAIR
#undef USE_PMS5003
#undef USE_NOVA_SDS
#undef USE_PZEM004T
#undef USE_SERIAL_BRIDGE
#undef USE_SDM630
#undef USE_IR_REMOTE
#undef USE_WS2812
#undef USE_ARILUX_RF
#undef USE_SR04
#undef USE_TM1638
#undef USE_RF_FLASH

#endif  // _USER_CONFIG_OVERRIDE_H_

@pablitofernandez
Copy link

@pszafer I think this is more a HA related issue. Im not at home right now so I cant test it, but you could try calling shutterstop on the home assistant start event. This way you force a new tele message from Sonoff whenever HA starts.

@pszafer
Copy link

pszafer commented Aug 22, 2018

I'm doing it, like this. Just suggested that maybe it could be avoided.

- id: '1534948330397'
  alias: Check cover at startup
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      topic: cmnd/window/shutterposition
    service: mqtt.publish

@B1G1
Copy link

B1G1 commented Aug 22, 2018

Hi @pszafer,
This is not needed with the last version.
There’s a new SHUTTER1 retained message

@pszafer
Copy link

pszafer commented Aug 22, 2018

@B1G1 , I'm litte confused now.
Which MQTT topic are you talking about? Do I need to config something to have retained flag?

tele/%topic%/SENSOR

or

stat/%topic%/RESULT

or

tele/%topic%/RESULT

@B1G1
Copy link

B1G1 commented Aug 22, 2018

You have to use
stat/%topic%/SHUTTER1
as state_topic
Read this #53 (comment)

@pablitofernandez
Copy link

@stefanbode Is there any possibility you could enable the minimal version of your firmware so I can upload it via OTA? When now I try to upload the sonoff full version I receive the buffer error.

@pszafer
Copy link

pszafer commented Aug 23, 2018

@pablitofernandez undef unnecessary modules.
My firmware has 396KB, so I can update it pretty easy.

@pablitofernandez
Copy link

@pszafer How can I do that? And how do I know which modules are unnecesary? thanks!!

@pszafer
Copy link

pszafer commented Aug 23, 2018

Use user_config_override.h from my previous post.
#57 (comment)

If you don't use IR I guess you don't need IR remote etc. :)

@pablitofernandez
Copy link

Thanks @pszafer !!! It worked as you said. But now I have a problem, I have this settings in Home Assistant:

   - platform: mqtt
    name: "Persiana del dormitorio"
    availability_topic: "tele/persiana_dormitorio/LWT"
    state_topic: "stat/persiana_dormitorio/SHUTTER1"
    command_topic: "cmnd/persiana_dormitorio/backlog"
    set_position_topic: "cmnd/persiana_dormitorio/shutterposition"
    qos: 1
    retain: true
    payload_open: "SHUTTEROPEN"
    payload_close: "SHUTTERCLOSE"
    payload_stop: "SHUTTERSTOP"
    state_open: "ON"
    state_closed: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: true

I can see the shutterposition updating but when I restart HA is not retained.

@B1G1 can you help?

@B1G1
Copy link

B1G1 commented Aug 23, 2018

Did you set powerretain 1 in console?

@pablitofernandez
Copy link

Ok my bad! I set powerretain 1 in console and now its working perfectly. Thank you all for this excellent job!!!!!

@B1G1
Copy link

B1G1 commented Aug 23, 2018

In my HA config, instead, i set retain: false because sometimes mqtt broker was retaining messages and restarting HA it sent uwanted commands

@pszafer
Copy link

pszafer commented Aug 23, 2018

Hopefully, soon we will be able to set position from HA even if cover is fully open or close.
Look out for PR home-assistant/core#16148

stefanbode pushed a commit that referenced this issue Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants