Hi!
So I have been running Homey Pro for my home automation for some time now but I do have some stability issues and a lot of integrations that I want are just not available, therefor I’m starting to lean towards Home Assistant to do the job instead. I have read and watched a lot of videos but something still feels a bit off to me and I hope you can give me some better insight.
My questions are mainly regarding automations, more specifically, semi-advanced stuff where things are activated based on a lot of different states, variables and other conditions.
AFAIK there are
3 different UI-ways of automating (Scipts, scenes and automations), all 3 of which seem quite combersome since there are just a load of options to fill out, feels like filling out a massive form.
Node red which seems pretty nice but still has quite an messy way of accessing/viewing things compared to the “flows” system in Homey Pro.
YAML files which seems to require quite a lot of code for simple things and would quickly become quite large for fairly advanced scripts.
Are these the only ways of creating automations? No script language for basic code with if/else switches, function calls, for/while loops etc?
Most things in my home can probably be accomplished fairly easy with basic triggers and what not, but some are a bit more complex where I would want a more top down view of what is actually going on.
One example is the full control of everything inside and outside my chicken coop which currently follow this simple pseudo code: (What I currently have going in Homey)
while(true) // Every 5 mins
{
inTemp = sonoff1.temperature()
bDoorOpen = omletDoor.openStatus
outTemp = -> sonoff2.temperature()
lightLevel = omletDoor.getLightLevel(); // 0-100%
// Global variable that I can adjust on demand
variable_minTempHeater1 = 6 // degrees celsius
// Global variable that I can adjust on demand
variable_minTempHeater2 = 4 // degrees celsius
// Open door when outside temperature is warm enough and its day time
if(outTemp > 1 && system.time > 06:00 && system.time < 20:00)
{
if(omletDoor_device.openDoor() == success)
bDoorOpen = true;
else
sendNotification("failed to open door");
}
// Close door when its night time
else if(system.Time > 20:00 && system.time < 06:00)
{
if(omletDoor_device.closeDoor() == success)
bDoorOpen = false;
else
sendNotification("failed to close door");
}
// Notify me when the chickens are left outside in the cold
if(bDoorOpen && outTemp < 0)
sendNotification("Go and chase the chickens inside and close the door!");
// Start first heater when a bit cold and the door is closed
if(inTemp < variable_minTempHeater1 && bDoorOpen == false)
{
if(heater1.turnOn() != success)
sendNotification("Failed to turn on heater 1");
}
else if(heater1.TurnOff() != success)
sendNotification("Failed to turn off heater 1");
// Start second heater when even colder and the door is closed
if(inTemp < variable_minTempHeater2 && bDoorOpen == false)
{
if(heater2.turnOn() != success)
sendNotification("Failed to turn on heater 2");
}
else if(heater2.TurnOff() != success)
sendNotification("Failed to turn off heater 2");
// Make sure the outdoors lamp is on when its dark outside and the chickens are outdoors.
if(bDoorOpen && lightLevel < 90)
coopLight.TurnOn();
// Similar logic for other devices inside and outside the coop, lights, water heaters, camera with motion detection etc.
Wait(300); // Wait 5 mins for next trigger
}
In Homey Pro I get a very nice view of all this like this, would be great if there was something similar (with similar i mean the way you can easily follow the logic, the code above is even easier for me since i’m used to code in C++, YAML is not really intuitive for my old coder brain)
Scripts and automations are your builtin automations.
Automations are nothing more than a script thag has a trigger. I use them almost exclusively for triggers.
Yaml is the text storage form and used as a script language. If you’re old coder this is your bag. It’ll feel very ‘basic’ with some extended commands. Everything is there.
No - you don’t have a main loop ha does all that for you just worry about triggers and states.
If you like pretty flow based automation yih may choose NR instead. Pros flow based graphic build if you are into that. Cons way more complexity and debatable harder to troubleshoot (you added another platform in and can’t use the builtin trace tools - harder imho)
With anyone moving platforms. I urge you to sit with your automations and list them by what they do NOT HOW THEY DO IT. Because I guarantee the how will change. (especially seeing how yours has thag big loop) Then go through how you do each thing in HA.
You must try very hard to stay away from the trap of well - platform x did it this way so -
HA is fundamentally a state engine and works well with triggers and events. It does poorly running a clock with wait states and loops.
So first you need to sit and think about what needs to port. Then for each - thing - research HA in how to do that thing.
Yeah I know it’s not quite the question you asked but it’s probably the answer you actually need.
Thanks for the reply,
These are all fair points and I’m used to adapt and think about things from different angles so that should not be an issue.
Maybe I will look more into YAML then, I guess we can trigger code from other YAML-files to effectively create function calls and maybe even trigger scenes and scripts from there as well?
What strikes me though is when you say “no” to the main loop, how does HA guarantee that a device gets the state it is supposed to have if for example power dies before a time was supposed to trigger an event and the power gets back on 1 hour later, way past the trigger time? These are the types of events I have the main loop for in Homey since Homey cannot know what was “supposed to happen” while the power was out, or when another device failed for whatever reason, making other triggers not triggering etc.
Use individual scripts as your - functions they can call each other.
Inside scripts they call actions - formerly services an action is basically a do clause with meta about what to do in a structured JSON dict.
Don’t scope automations on devices if you want your automations to survive device replacement. Use entity_id device id’s are immutable and on device replacement you’ll be hunting scripts for a guid you’ll never find. If you scope on entity instead the human readable entity I’d is the key and you can swap devices simply by renaming the entities…
Scripts can have loops conditions (very complicated ones) and transform data…
All the things you’re looking for are there you just need the vocabulary…
I highly respect @NathanCu’s knowledge and advice, but in this case I’ll push back slightly…
Node Red isn’t just for “pretty”… it’s an excellent automation engine that, at least for some, is neither more complex nor harder to troubleshoot. (Nor is accessing it “messy”!) Whether you prefer NR or the native HA automation engine, is, in my opinion, a matter of how your brain works. Some folks grok things much better as structured text - for them the native engine + YAML are going to be better. For other folks though, the visual aspects of NR make it just easier and more intuitive to grasp the logic of an automation.
As a newcomer to HA, try a few automations in both environments. Then stick with the one that makes more sense to you.