Automation During Date Range

Very nicely done. Im going to have to look closer at template syntax in the future. Is it right that the template stuff is tasmota driven? Whereas all the code around it is home assistant specific?

What language does tasmota talk vs HA?

Really appreciate the help!!

Phils Template is pure Home Assistant. Tasmota has ‘rules’ you can use however I only use Home Assistant stuff with all mine.

Tasmota communicates with HA via MQTT.

1 Like

Ok. Thanks for that quick response Dave. Ive just seen some template type stuff in a field on the tasmota flashed sonoff basics, which made me think it was tasmota scripting vs HA.

Are home assistant templates python, perl, bash, or something else? Or just their own special home grown flavor?

The template stuff for Tasmota is entered in Tasmota to set the device type on a once-off basis. Nothing to do with HA templates… completely different function.

Home Assistant generally uses Jinja templates but some addons/custom-cards use Java. You can also use scripts (I have used bash and Python but I assume you could use Perl too - the trick is to make sure the used commands are supported by the Home Assistant shell)

I see in configuration | other in the sonoff/tasmota there is is this below, under template, but template isn’t active…

{“NAME”:“Generic”,“GPIO”:[255,255,255,255,255,255,255,255,255,255,255,255,255],“FLAG”:15,“BASE”:18}

what is this stuff for?

Also, what scripting language is HA most like? Python/Perl/bash?

thanks.

The template sets the GPIO Port outputs. 255=user and that is a Generic sonoff and not active as per what you say. If you set the module type, it will overide that template.
See here:
Here is my nodemcu:


It has these GPIO Settings:

I configured it using this template:

{"NAME":"NodeMCU","GPIO":[0,0,0,0,6,5,0,0,0,0,0,0,0],"FLAG":0,"BASE":18}

On the Template page you can click on the dropdown menu for each GPIO to see what the options are for that pin.

As well as the preconfigured modules, there is a site you can download templates for pretty much any device or you can roll your own as I have done here.

HA uses Python scripting.

As @DavidFW1960 said, HA templates are written in Jinja2. But note that you can use a lot of Python within Jinja2 templates as well.

HA has two main scripting choices. HA’s native Scripts and fairly restricted Python Scripts. HA also lets you call Shell commands, so…

honestly… this is french to me. GPIO’s are the places i can solder wires on the device i’m using, correct? when you define GPIO4 and 5 above, what kind of data/function is actually moving through these pins? how did you know what an SDA and an SCL are? (yeah. pretty noob!).

Also, why is Generic (18) used? on my sonoff-basic there is an option for that… but i’m on generic (18) as well instead of that. mine are all 255?

it works in HA, but i’d just like to know the why… (why are those two red?) i have a lot of why’s!

Well you see SCL and SDA - those pins enable me to connect i2c devices and they are connected physically to those GPIO’s (See the temp/pressure/humidity/illuminance)

Yours is set to Generic (18) as the module type because that is the default and you have not selected the correct module type. 255=user is the default!
No idea why 9/10 are red.
If you go to configure>configure module you can select the correct module type and it won’t say generic anymore.

oh and generic(18) shows on mine because that was the name of the base template I modified.

Have you ever done a Tuya Dimmer (treatLife DS01C)? I have it flashed, up and running, but in the switch console i dont get a slider… i’m using Tuya MCU(54), but i cant find any references for what to set all the GPIO’s to. running the lastest tasmota 7.1.2.

thanks.

so, i found some magic.

https://blakadder.github.io/templates/treatlife-DS02S.html

** Enter this command to get the dimmer working and the allow the buttons to work if the switch is off: BackLog TuyaMCU 21,2;SetOption20 1;SetOption54 1

I was initially concerned because i had the TreatLife DS01C but it seems to be working ok.

Never used one of those - Blackadder has templates for most everything.

got a dimmer that’s consistent that you like better?

also, do you program 3-way’s or do they make 3 way switches?

motion sensors that you like?

tired of the 20 questions yet?

help much appreciate. ty

I have basic plugs some sonoff sv’s and a nodemcu as well as a few lights. No dimmers etc (I can dim via ha without a dimmer anyway)

do you just use dimmable lights?

Yes they are dimable and I can use scenes or scripts to set the brightness/colour etc

The only reason i’m not too excited about dimmable lights is that i can’t stomach paying $10+ for a single bulb. i’m actually using wifi dimmers and incandescent lights - lol…

Looking into motion sensors now. Anything working well or not for you? i also have some fan/lights with a single switch leg coming into the wall switch. looking for a something i could put up on in the fan to separate the two.

Well you asked…

I don’t use motion sensors either.

If anybody else is looking at this date range conditions, you might also consider this:

- alias: Water Plants daily within certain dates
  trigger:
    platform: time
    at: "19:00:00"
  condition:
    - condition: template # Only between these dates
      value_template: >
        {% set from = '1.2.2020' %}
        {% set to = '2.2.2020' %}
        {{ as_timestamp(strptime(from,"%d.%m.%Y")) 
          <= as_timestamp(now()) <
          (as_timestamp(strptime(to,"%d.%m.%Y"))+60*60*24) }}
  action:
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.flower_pump

Hope you find it useful.

2 Likes