Changing a variable in tasmota

Im new to HA and i am trying to integrate a tasmota project that i set up last year for my pool. I use a Tasmota flashed Sonoff TH16 to monitor the temperature in my pool. It sends the temperature value via MQTT to my Tasmota flashed Sonoff 4chpro. ie: var1=75.

My 4chpro has are rule to maintain the temperature that is set as mem1. For example i set mem1 = 75 and the rule compares the value of of mem1 against the value from the temperature sensor Var1 and turns the heater on or off accordingly.

What i want to do with HA Lovelace is ad something like a slider , guage, etc that i can adjust to send an MQTT message to the 4chpro to set the value of mem1. Effectively the 4chpro is a thermostat and i want to be able to adjust it.

Any help is appreciated.
Thanks in advance

JG

Hi there, this particular requirement has two parts. First is to have a slider which can be made with input_number entity. for this copy the following to config and restart.

input_number:
  slider:
    name: Slider
    min: 0
    max: 100
    step: 1

BTW you can change the name of slider and entity_id or any parameters according to your wish.
Next would be to create an automation to send mqtt message when there is a change of this slider value. Please copy this automation.

alias: Tasmota Temperature Setting
description: ''
mode: single
trigger:
  - platform: state
    entity_id: input_number.slider
condition: []
action:
  - service: mqtt.publish
    data:
      topic: cmnd/<mqtt_topic>/Mem1
      payload_template: '{{states(''input_number.slider'')}}'

Please change the mqtt topic and also the entity id of slider if you have change it.

If you need help copying automation, please see the gif.

Thanks so much for this but im confused. How do i get the slider on to my dashboard?

You can use the entities card which is a native card in HA. Please see the gif.

You can also go for custom cards which would give you better control and appearance options but you will have to install them either through HACS or directly. If you want such an option please check out this card.


If anything please do ask.

Thanks, with a little exploration i was able to figure that out.
So now my next question is this:
I have an “on” timer and an “off” timer. I would like to display these times on my dashboard. The control publishes these times as son4ch/timer1 and son4ch/timer2
How do i take the payload of these two messages and display them in my dashboard?
thanks so much for the help

You can use a mqtt sensor for this function. I believe the timer mqtt payload would be like this

{"Timer1":{"Enable":1,"Mode":2,"Time":"00:01","Window":0,"Days":"1111111","Repeat":1,"Output":1,"Action":1}}

In this case the mqtt sensor would look like this.

sensor:
  - platform: mqtt
    name: "Timer1"
    state_topic: "son4ch/timer1"
    value_template: "{{value_json.Timer1.Time}}"
    force_update: true

So as long as you dont mind answering, i will ask away.
Last year when i built this pool controller, i was able to set it up using node red. I found many restrictions with NR that made it the wrong platform for me. It has been a year and i basically started all of this from scratch. So far i am moving along alright but have hit a few stumbling blocks.
To begin with, I am able to use the slide to change the temperature setting on my tasmota. It works well. My issue is that if i reboot the HA raspberry, the displayed result shows as “unknown”. Now as i recall i can set an mqtt message to “retain” so that it will be retrieved as soon as i boot up my client. I just dont recall how to do that. Also as i remember using the retain flag can become troublesome. Is there a way i can have home assistant poll my tasmota for this information at a set time interval?

Always happy to help… :innocent:I think the best way would be set automation like this.

alias: Hassio Start Sync
trigger:
  - event: start
    platform: homeassistant
condition: []
action:
  - data:
      payload: check
      topic: cmnd/tasmotas/state
    service: mqtt.publish
  - delay: '00:00:05'
  - data:
      payload: check
      topic: cmnd/tasmotas/POWER
    service: mqtt.publish
mode: single

This automation is triggered soon after HA restarts and the function of this is to call states info from all devices. In the above automation instead of calling each and every device by their mqtt topic, I have used the group topic tasmotas. Please note I have already set the group topic of all my tasmota devices as tasmotas earlier itself. You can try group topic way or call the devices by topic name.

Im a little bit lost here. Where do i put this in? Does it go in automations.yaml or configuration.yaml?

Is there anything i need to add to it such as an id? I have tried adding it in both places and both throw an error.

I have read that the automations can be places in either of the above files but the instruction isnt clear on how to do it…

I have made a changes to the above automation. I accidently had omitted a line earlier, now its working, please copy it to automations as we did in the previous case and try.

The tasmotas in the above topic is the mqtt group topic. Mqtt group topic is a feature that is provided by tasmotas to give a single command to a number of tasmota devices at once. This is achieved by making the group topic same for all the tasmota devices. To set the group topic in tasmota devices, go to tasmota device webpage and then to console and enter the command GroupTopic tasmotas . This will make tasmotas as the group topic of the device. you have to repeat this for all the tasmota devices.

I will explain how this helps. The major prbolem with tasmota devices is that on HA restart it takes time for the device to update the state. This is because in tasmota devices the state updates are controlled with teleperiod command which is default to 5minutes. So it would take upto 5 minutes for the device to get updated after HA restart. You can solve this by making the teleperiod very less to about 10s but this will make the mqtt broker busy.

The solution id the automation I have given. As soon as HA restarts this automation calls all tasmota devices with the group topic tasmotas to update the state.

This isnt working for me. This is what i have in my automations.yaml

- id: '1616787470564'
  alias: Tasmota Temperature Setting
  description: ''
  trigger:
  - platform: state
    entity_id: input_number.slider
  condition: []
  action:
  - service: mqtt.publish
    data:
      topic: cmnd/son4ch/Mem1
      payload_template: '{{states(''input_number.slider'')}}'
      retain: 'true'
  mode: single

- id: '1617195222898'
  alias: Turn On Pump
  description: ''
  trigger:
  - platform: state
    entity_id: input_datetime.only_time
  condition: []
  action:
  - service: mqtt.publish
    data:
      topic: cmnd/son4ch/timer1
      payload_template: '{{states(''input_datetime.only_time'')}}'
      retain: 'true'
  mode: single
  
  alias: Hassio Start Sync
trigger:
  - event: start
    platform: homeassistant
condition: []
action:
  - data:
      payload: check
      topic: cmnd/tasmotas/state
    service: mqtt.publish
  - delay: '00:00:05'
  - data:
      payload: check
      topic: cmnd/tasmotas/POWER
    service: mqtt.publish
mode: single

My error log shows me this

2021-04-01 09:03:09 ERROR (SyncWorker_1) [homeassistant.util.yaml.loader] while parsing a block collection
in "/config/automations.yaml", line 1, column 1
expected <block end>, but found '?'
in "/config/automations.yaml", line 32, column 1
2021-04-01 09:03:09 ERROR (MainThread) [homeassistant.components.hassio] Error loading /config/configuration.yaml: while parsing a block collection
in "/config/automations.yaml", line 1, column 1
expected <block end>, but found '?'
in "/config/automations.yaml", line 32, column 1

delete this from config and add the automation like this.

That advisory applies to command topics in Home Assistant, not state topics published by the device itself. Your device can safely publish its temperature to a topic as a retained message. The setting for that is on the Tasmotized device and not in Home Assistant.

The device’s published temperature will be stored (retained) by the MQTT Broker. When Home Assistant is restarted, the moment it reconnects to the Broker it will instantly receive the stored temperature value.

This is not working. See the error in my screen shot below

You have added space in front of alias which is not accepted. Please remove that and try

Thanks, that was it. Im not sure about the payload though. You have “check” written there which shows as exactly that on my dashboard. What i need is the value in that topic.
This system has quite a learning curve (for me anyway).

Payload is not important, you can just leave it empty like below this instead of using check.

payload: ''

For anyone else reading this thread, it’s unnecessary to poll a Tasmotized device when communicating via MQTT.

All you need to do is ensure the device publishes its payload as a retained message. Upon restart, Home Assistant will reconnect to the broker and immediately receive the device’s retained message (no polling required).

  • If your Tasmotized device is using a Rule to publish a value to a specific topic, ensure it’s using the Publish2 command.
  • If you rely on the tele topic, you can instruct Tasmota to publish its payloads to tele as a retained message by setting SensorRetain to 1.

I am making progress very slowly. My next hurdle is that i need a way to enter a time for timer1 and timer2 on the tasmota. The message over mqtt has to get to the tasmota in the format timer1 {time:“02:00”}. I put a input_datetime.only_time card on my dashboard and created the following automation

alias: Set Timer
description: ''
trigger:
  - platform: state
    entity_id: input_datetime.only_time
condition: []
action:
  - service: mqtt.publish
    data:
      topic: cmnd/son4ch/timer1
      payload_template: '{\"timer1\"{states(''input_datetime.only_time'')}}'      
      retain: 'true'
mode: single

No success.
Anyone?
Thanks in advance

JG

Like this:

      payload_template: "{\"timer1\":\"{{states('input_datetime.only_time')[:5]}}\"}" 

The state value of your input_datetime is in this format:
HH:MM:SS
Tasmota requires this:
HH:MM
Therefore we only need the first 5 characters and so we use python’s ability to slice a string. That’s what the [:5] does in the template.

In addition, your template had mismatched brackets and lacked the required colon between the JSON key and value.